,http://developer.android.com/resources/tutorials/views/hello-listview.htmlAndroid的有基于Android中HELLO-的ListView turorial没有ListView控件适配器RESOURCEID
在setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
有一个错误,因为没有R.layout.list_item
以前我按照教程创建了res/layout文件夹中的文件list_item.xml
<?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>
它不具有不同的名称既不是(main_list_view.xml)工作
这是完整的源
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)); //<<
}
更新! 现在在创建新项目时,它的作品!当我在第一个项目中使用File> new> Android XML File时,它不起作用,但是现在在不同的项目中,我使用file> new> File,也许这是一个可能的错误?
那么你的res/layout目录中有一个文件名为list_item.xml? – 2010-09-29 16:42:17
是的,当然,在res/layout目录res/layout/list_item.xml中,bulp指出“list_item无法解析或不是字段” – 2010-09-30 07:44:04
现在创建新项目时,它的作品!当我在第一个项目中使用File> new> Android XML File时,它不起作用,但是现在在不同的项目中,我使用file> new> File,也许这是一个可能的错误?哦,它似乎不是一个错误,在新的情况下,我尝试了与XML和它正常工作! – 2010-09-30 07:50:29