這是我的主要活動ListActivity錯誤:「很遺憾,您的應用程序已停止」
public class MainActivity extends ListActivity {
private String [] mainScreenList = {"Portal","Settings","Help","About"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> mainScreen = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_activated_1, android.R.id.text1,mainScreenList);
ListView lv = (ListView) findViewById(R.id.listView);
lv.setAdapter(mainScreen);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
String pen = o.toString();
Toast.makeText(this, "You have chosen the pen: " + " " + pen, Toast.LENGTH_LONG).show();
//get selected items
/* if(position==0)
{
Intent i = new Intent(this, DataEntryActivity.class);
startActivity(i);
}else if(position==1)
{
Intent i = new Intent(this, DataEntryActivity.class);
startActivity(i);
}else if(position==2)
{
Intent i = new Intent(this, DataEntryActivity.class);
startActivity(i);
}else if(position==3)
{
Intent i = new Intent(this, DataEntryActivity.class);
startActivity(i);
}*/
}
}
目前我只是想顯示選擇列表視圖項的名稱代碼。
這是XML代碼
<?xml version="1.0" encoding="utf-8"?>
<ListView
android:id="@android:id/list"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.bernine.practicalsessions.MainActivity">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
</ListView>
當運行它說的應用「不幸的是,應用程序已經停止。」
POST錯誤日誌.. –
需要錯誤日誌..裏面的ListView – Mohan
列表視圖.. ???? – Dinash