适配器中的GetView永远不会被执行

时间:2014-10-25 22:12:36

标签: android user-interface android-arrayadapter

我的自定义适配器中有以下代码。我试图在CheckedTextView中设置文本,但它不起作用。当我使用调试器时,我可以看到getView和getCount永远不会被调用。怎么了?

public class AccessPoint extends ArrayAdapter {

    private List<String> name  = new ArrayList<String>();

    public AccessPoint(Context context, int textViewResourceId, List<String> objects) {
        super(context, textViewResourceId, objects);
        this.name.addAll(objects);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return name.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return name.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
          CheckedTextView textView = (CheckedTextView) convertView.findViewById(R.id.text);
          textView.setText(name.get(position));
        return convertView;
    }

}

这是我向listview添加适配器的方式:

accessPoints.add(new AccessPoint(getBaseContext(), 2131361936, objects));

        accessPointsListView.setAdapter(new ArrayAdapter<AccessPoint>(this, layout.access_point, accessPoints));

我的xml文件,它位于listview中:

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:drawablePadding="8dp"
android:drawableLeft="@drawable/image1"
android:gravity="center_vertical"
android:paddingLeft="2dip"
android:id="@+id/text"
android:paddingRight="2dip"
android:textAppearance="?android:attr/textAppearanceMedium" />

0 个答案:

没有答案