我正在尝试让Listview变为可点击,但如果有任何方法/函数被调用,它会立即崩溃,如toast();
listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, arrayListCarros);
mainListView.setAdapter( listAdapter );
db.close();
mainListView.setClickable(true);
mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
toast(position);
}
});
答案 0 :(得分:0)
mainListView.setClickable(true);
mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Toast.makeText(activityname.this, String.valueOf(position), Toast.LENGTH_SHORT).show();
Intent intent = new intent(activityName.this,targerActivity.class);
activityName.this.startActivity(intent);
}