Not working with custom Grid Adapters (baseadapter)
Opened this issue · 5 comments
nullpointer exception on grid view custom baseadapter @felipecsl
Me too. Not working with BaseAdapter.
I get NPE in QuickReturnAdapter getView() method. It's on this line:
v = wrappedAdapter.getView(position - numColumns, convertView, parent);
I'm also using BaseAdapter. Did anyone find solution for this issue ?
does any body have a solution for this?
As mentioned you need to wrap the adapter using:
// Wrap your adapter with QuickReturnAdapter
listView.setAdapter(new QuickReturnAdapter(adapter));
e.g:
In my case I use custom adapter which extends BaseAdapter:
public class CustomAdapter extends BaseAdapter {
...
}
now you just need to wrap it using his method and it will look like this:
listView.setAdapter(new QuickReturnAdapter(new CustomAdapter(params)));
Okay I just make things short but I guess this will be understandable. The next thing you need to be concerned is the on item click listener. In my case I use a custom GridView which adds up a header view see https://github.com/liaohuqiu/android-GridViewWithHeaderAndFooter
I thik this will happen even on a normal Grid or ListView that it will return an incorrect index so I just added this line cause I assume this library manually adds a header view on your list:
content.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position - (getResources().getInteger(R.integer.gallery) * 2)>=0) { //ensure that there will be no out of bounds exception
//library for the quick return seems to add it's own header but failed since it may gone missing when added with items.
//computation is now the positions minus the gallery size multiplied by 2 since it will just create two rows 1 for header 40dp and 1 for the quick return that has a 0dp
System.out.print(position - getResources().getInteger(R.integer.col_count));
}
}
});
Is there any solution ????