質問

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