Your content must have a ListView whose id attribute is 'android.R.id.list'

后端 未结 7 1389
清歌不尽
清歌不尽 2020-11-22 04:07

I have created an xml file like this:




        
相关标签:
7条回答
  • 2020-11-22 04:36
    <ListView android:id="@id/android:list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="false"
            android:scrollbars="vertical"/>
    
    0 讨论(0)
  • 2020-11-22 04:39

    Rename the id of your ListView like this,

    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
    

    Since you are using ListActivity your xml file must specify the keyword android while mentioning to a ID.

    If you need a custom ListView then instead of Extending a ListActivity, you have to simply extend an Activity and should have the same id without the keyword android.

    0 讨论(0)
  • 2020-11-22 04:45

    Exact way I fixed this based on feedback above since I couldn't get it to work at first:

    activity_main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@android:id/list"
    >
    </ListView>
    

    MainActivity.java:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    addPreferencesFromResource(R.xml.preferences);
    

    preferences.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
    <PreferenceCategory
        android:key="upgradecategory"
        android:title="Upgrade" >
        <Preference
            android:key="download"
            android:title="Get OnCall Pager Pro"
            android:summary="Touch to download the Pro Version!" />
    </PreferenceCategory>
    </PreferenceScreen>
    
    0 讨论(0)
  • 2020-11-22 04:54
    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
    

    this should solve your problem

    0 讨论(0)
  • 2020-11-22 04:55

    Inherit Activity Class instead of ListActivity you can resolve this problem.

    public class ExampleActivity extends Activity  {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.mainlist);
        }
    }
    
    0 讨论(0)
  • 2020-11-22 04:56

    You should have one listview in your mainlist.xml file with id as @android:id/list

    <ListView
        android:id="@android:id/list"
        android:layout_height="wrap_content"
        android:layout_height="fill_parent"/>
    
    0 讨论(0)
提交回复
热议问题