Вопрос

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.

Это было полезно?

Решение

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.

Другие советы

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..........");
    }
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top