Android自定义阵列适配器未运行

Android自定义阵列适配器未运行,android,Android,您好,我已经创建了一个自定义阵列适配器来填充一个列表,当我运行应用程序时,它没有崩溃,但什么都没有发生。我尝试在适配器内部实现日志,以查看它得到了哪个部分,但它没有运行任何部分?是否有人知道A.我做错了什么或B.如何正确实现自定义阵列适配器 这是我的适配器 import java.util.ArrayList; import android.content.ClipData.Item; import android.content.Context; import android.util.Lo

您好,我已经创建了一个自定义阵列适配器来填充一个列表,当我运行应用程序时,它没有崩溃,但什么都没有发生。我尝试在适配器内部实现日志,以查看它得到了哪个部分,但它没有运行任何部分?是否有人知道A.我做错了什么或B.如何正确实现自定义阵列适配器

这是我的适配器

import java.util.ArrayList;

import android.content.ClipData.Item;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DocumentArrayAdapter extends ArrayAdapter<String> {



    // declaring our ArrayList of items
    private ArrayList<String> docTitles;
    private ArrayList<String> docTypes;
    private ArrayList<String> docModified;
    /* here we must override the constructor for ArrayAdapter
    * the only variable we care about now is ArrayList<Item> objects,
    * because it is the list of objects we want to display.
    */
    public DocumentArrayAdapter(Context context, int layoutResourceId, ArrayList<String> docTitles, ArrayList<String> docTypes, ArrayList<String> docModified) {
        super(context, layoutResourceId);
        this.docTitles = docTitles;
        this.docTypes = docTypes;
        this.docModified = docModified;

    }

    /*
     * we are overriding the getView method here - this is what defines how each
     * list item will look.
     */
    public View getView(int position, View convertView, ViewGroup parent){

        // assign the view we are converting to a local variable
        View v = convertView;
        Log.v("Main","v, = " + v);
        // first check to see if the view is null. if so, we have to inflate it.
        // to inflate it basically means to render, or show, the view.
        if (v == null) {
            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.document_cell, null);
        }

        /*
         * Recall that the variable position is sent in as an argument to this method.
         * The variable simply refers to the position of the current object in the list. (The ArrayAdapter
         * iterates through the list we sent it)
         * 
         * Therefore, i refers to the current Item object.
         */
        String title = docTitles.get(position);
        String types = docTypes.get(position);
        String modified = docModified.get(position);

        Log.v("Main","DocumentArrayAdapter, = " + title + " " + types + " " + modified);

        if (title != null) {

            // This is how you obtain a reference to the TextViews.
            // These TextViews are created in the XML files we defined.

            TextView docTitle = (TextView) v.findViewById(R.id.name);
            TextView docType = (TextView) v.findViewById(R.id.doctype);
            TextView docMod = (TextView) v.findViewById(R.id.modified);
            ImageView docImage = (ImageView) v.findViewById(R.id.docicon);


            // check to see if each individual textview is null.
            // if not, assign some text!
            if (docTitle != null){
                docTitle.setText(title);
            }
            if (docTypes != null){
                docType.setText(types);
            }
            if (docTitle != null){
                docMod.setText(modified);
            }


        }

        // the view must be returned to our activity
        return v;

    }} 
改变这个

 super(context, layoutResourceId);

您还应该考虑使用<代码> ViewHolder <代码>模式进行平滑滚动和性能。


在适配器构造函数中 layoutInflater=layoutInflater.from(上下文)


@如果您感兴趣,请检查listview如何回收视图。当网站允许你回答时,一定要接受答案。
 super(context, layoutResourceId);
 super(context, layoutResourceId,docTitles);
public View getView(int position, View convertView, ViewGroup parent){

if (convertView == null) {

                convertView = layoutInflater.inflate(R.layout.activitylayout,
                        null);

holder = new ViewHolder();

                holder.tt = (TextView) convertView.findViewById(R.id.toptext);




}else {

                holder = (ViewHolder) convertView.getTag();
            }



holder.tt.setText(text);

return convertView;

}