Question

Has anyone know proper way to retrieve number of items stored in ListAdapter? Here is dim one (it works):

int count = ((ArrayAdapter<Object>)getAdapter()).getCount();

Where this is an instance of complex view like GridView or ListView constructed with data from ListAdapter and getAdapter() returns ListAdapter.

Was it helpful?

Solution

Thanks guys. The solution is even simpler (I have realized it after reading an answer above):

int count = getAdapter().getCount();

The reason is that ListAdapter interface the return of getAdapter() call is inhereted from Adapter interface which has declared getCount() method already.

OTHER TIPS

listview.setOnItemClickListener(new OnItemClickListener() 
{
    public void onItemClick(AdapterView<?> lv, View item, int position,   long id) 
    {
        ListView lView = (ListView) lv;
        Adapter adapter = (MyAdapter) lView.getAdapter();
        int i = adapter.getCount();
        System.out.println(i + ".....size..........");
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top