I'm trying to write a list view on Android, but there's an error.

Asked 2 years ago, Updated 2 years ago, 115 views

I'm going to write a list view Compilation works well

Your content must have a ListView whose id attribute is 'android.R.id.list' If you get this kind of error, it will explode if you execute it.

My source is

<ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.8"></ListView>

m_Adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, new_name); listView = (ListView) findViewById(R.id.list);

 What's the problem?

android listview

2022-09-22 22:13

1 Answers

I think the current activity is ListActivity. In case of ListActivity, The id of the list view should be as below.

 <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.8"></ListView>

You have to register it like this. And listView = (ListView) findViewById(android.R.id.list); You have to fix this part like this, too.


2022-09-22 22:13

If you have any answers or tips

Popular Tags
python x 4647
android x 1593
java x 1494
javascript x 1427
c x 927
c++ x 878
ruby-on-rails x 696
php x 692
python3 x 685
html x 656

© 2024 OneMinuteCode. All rights reserved.