0
當我運行應用程序,並單擊列表視圖,拋出一個Exception
這樣的:如何設置listview onclick?
12-03 07:57:34.258: E/AndroidRuntime(681): java.lang.ClassCastException: android.widget.RelativeLayout
主要的代碼是:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.setTitle("BaseAdapter for ListView");
listView = (ListView) this.findViewById(R.id.MyListView);
listView.setAdapter(new ListViewAdapter(titles, texts, resIds));
listView.setClickable(true);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}
});
}