0

I have created a custom adapter that extends the BaseAdapter. Using this custom adapter I want to populate my listview. When I execute the code, getView method of my adapter doesn't get called. I have seen a lot of post on this but none of them helped. My adapter looks like this:

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;
}

}

The custom list item that I want in my list view looks like this:

<?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>

I have added the listview in the main.xml like this:

 <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>

and I have set the adapter to the listview like this:

  editLayersListView = (ListView)editModeLeftToolbarView.findViewById(R.id.home_activity_left_toolbar_editable_layers_listView);

    editLayersListView.setAdapter(new EditableLayersAdapter(baseActivity));

Please let me know what am I doing wrong as the getCount gets called but not the getView method.

Puneetr90
  • 179
  • 6
  • 18

0 Answers0