工作下面是相關代碼:OnItemClickListener不是ListView控件
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
未顯示。我哪裏錯了?
什麼你到底想做顯示烤麪包或點擊文本視圖,因爲問題是點擊列表視圖 –