“Content has view with id attribute 'android.r.id.list' that is not a ListView Class.” when create a list view in a fragment

后端 未结 3 1649
南笙
南笙 2020-12-19 03:32

Here is the problem. I have a list view, and it looks fine in the building, but it broke the error. Content has view with id attribute \'android.r.id.list\' that is not a Li

相关标签:
3条回答
  • 2020-12-19 03:52

    I was using:

    android:id="@+id/listView"
    

    Then, I have replaced to it:

    android:id="@android:id/list"
    
    0 讨论(0)
  • 2020-12-19 03:57

    I haven't added the listview into the XML

    Add a ListView with an android:id of @android:id/list to your layout, where you want the list to appear.

    Or, delete your onCreateView() implementation, so you get the inherited ListView that you get from ListFragment.

    Or, change your fragment to inherit from Fragment, not ListFragment and manage a ListView by yourself.

    Or, change your fragment to inherit from Fragment and do not attempt to show a list in it.

    0 讨论(0)
  • 2020-12-19 04:08

    You can inflate your View on onCreateView() method in which layout your ListView and id of that ListView must be

    @android:id/list
    

    and after that on onCreateView() method

    ListView lv = (ListView)contactLayout.findViewById(android.R.id.list);
    
    0 讨论(0)
提交回复
热议问题