문제

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