我创建了一个扩展BaseAdapter的自定义适配器。使用这个自定义适配器我想填充我的listview。当我执行代码时,我的适配器的getView方法不会被调用。我已经看过很多帖子,但没有一个帮助过。我的适配器看起来像这样:
public class EditableLayersAdapter extends BaseAdapter {
private List<EditLayerModel> editLayersList;
private BaseActivity baseActivity;
public EditableLayersAdapter(BaseActivity baseActivity) {
this.baseActivity = baseActivity;
this.editLayersList = ((HomeActivity) baseActivity).getEditGraphicsLayers();
}
@Override
public int getCount() {
return editLayersList.size();
}
@Override
public Object getItem(int position) {
return editLayersList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
convertView = baseActivity.getLayoutInflater().inflate(R.layout.edit_mode_editable_layers_list_item, null);
}
return convertView;
}
}
我在列表视图中想要的自定义列表项如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/edit_mode_list_item_radio_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
我在main.xml中添加了listview,如下所示:
<ListView
android:id="@+id/home_activity_left_toolbar_editable_layers_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/home_activity_left_toolbar_editable_layers_caption" >
</ListView>
我已经将适配器设置为listview,如下所示:
editLayersListView = (ListView)editModeLeftToolbarView.findViewById(R.id.home_activity_left_toolbar_editable_layers_listView);
editLayersListView.setAdapter(new EditableLayersAdapter(baseActivity));
请告诉我,由于getCount被调用而不是getView方法,我做错了什么。