这是相关代码:
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// storing string resources into Array
String[] menulist = getResources().getStringArray(R.array.menulist);
// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, menulist));
ListView lv = getListView();
// listening to single list item on click
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// selected item
String selected = ((TextView) view).getText().toString();
Toast toast=Toast.makeText(getApplicationContext(), selected, Toast.LENGTH_SHORT);//This is where the error shows
toast.show();
// Launching new Activity on selecting single List Item
/*Intent i = new Intent(getApplicationContext(), SingleListItem.class);
// sending data to new activity
i.putExtra("product", product);
startActivity(i);*/
}
});
这是 XML:
<?xml version="1.0" encoding="utf-8"?>
<!-- Single List Item Design -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/listgradient"
android:clickable="true"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
我保留了clickable
属性true
。但是Toast
没有显示。我哪里错了?