Android there is no ListView adapter resourceId

南笙酒味 提交于 2020-01-07 09:04:51

问题


based on Hello-ListView turorial in Android, http://developer.android.com/resources/tutorials/views/hello-listview.html

on the

setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));

had an error because there is no R.layout.list_item

previously i had followed the tutorial, created the file list_item.xml on the res/layout folder

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp">
</TextView>

it doesnt work with different name neither (main_list_view.xml)

this is the complete source

String[] appList;

ListView mainLv;    

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main); 
    appList = this.getResources().getStringArray(R.array.for_main_layout);
    mainLv = (ListView)findViewById(R.id.ListView01); 
    mainLv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, appList)); //<<
}

Updated! Ah its works now when creating new project! When i use File>new>Android XML File in the first project, it doesnt work, but now in different project, i use file>new>File, maybe is this a possible bug?


回答1:


it doesnt seem to be a bug, in new scenario I tried with the xml and it works normaly

So I just create a new project.

But I dont know the first.




回答2:


Have you tried Project -> Clean? the way it looks you're R.java isn't beeing updated, either project->clean or there is some error in xml most of times.




回答3:


You could have used the android supplied layout:

android.R.layout.simple_list_item_1

Try that one.



来源:https://stackoverflow.com/questions/3823684/android-there-is-no-listview-adapter-resourceid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!