How do you check if a ListView contains the specified title?

I tried using the ListView.indexOfChild (View view) method to check if the ListView contains the specified title view, but sometimes it returns -1 when the ListView really contains the specified title. Is there a better way to test this?

+5
source share
1 answer

If by title you mean the actual title added using any of the methods addHeaderView(...), you can simply get the number of titles added using getHeaderViewsCount().

Alternatively, if I remember correctly, it ListViewwraps its adapter internally HeaderViewListAdapterif it contains headers and / or footers. You can use getHeadersCount()to get the same number as above.


Change: . If you want to check if a specific title has been added, you can query for it HeaderViewListAdapter. You will need some criteria to verify.

, ListView 3 , (, HeaderListViewAdapter, ListView getItemAtPosition(...))) , . "" - , , , addHeaderView(...), Object. , , , , . . .

getItem(...)/getItemAtPosition(...) , . String , Java toString(), .equals(..).

, - mHeaderViewInfos ( ArrayList<ListView.FixedViewInfo>) .

+17