Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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..........");
    }
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top