错误。错误是:“应用程序意外停止”
我的第一个xml活动是visit_record.xml
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
我为此活动创建的课程是: visit_record.java
public class visit_record extends ListActivity {
static final String[] LIST = new String[] {"My Task", "Task Execution", "Non-Ticket Task"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.visit_record,LIST));
ListView listView = getListView();
listView.setTextFilterEnabled(true);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Intent intent;
switch (position) {
case 0:
intent= new Intent(visit_record.this, My_Task.class);
startActivity(intent);
break;
case 1:
intent=new Intent(visit_record.this, task_execution.class);
startActivity(intent);
break;
case 2:
intent=new Intent(visit_record.this, non_ticket_task.class);
startActivity(intent);
break;
default:
break;
}}
});
}}
请指导我为什么会出现错误,而不是在手机上运行应用程序。
答案 0 :(得分:2)
您已扩展ListActivity,当您这样做时,ListView必须具有标识android:id="@android:id/list"
。你错过了。
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
检查此question以获取更多详细信息。