开发者

Accessing @android:id/list ListView from code

开发者 https://www.devze.com 2023-03-26 09:38 出处:网络
In my Android application, I add a ListView element (for example) in the main.xml layout file this way:

In my Android application, I add a ListView element (for example) in the main.xml layout file this way:

<ListView android:id="@+id/myList">

Then I can access it from my M开发者_Python百科ainActivity using:

final ListView resultList = (ListView) findViewById(R.id.myList);

But how can I access such a ListView if I use the following ID in the layout file?

<ListView android:id="@android:id/list">

I want to access it from my MainActivity (which extends ListActivity).

Thanks in advance!


you can get it with ListView list = getListView(); from within your ListActivity


you can get it with ListView list = getListView();

Or:

(ListView)findViewById(android.R.id.list);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号