我遵循了此 answer 中提到的步骤为 ListView [listview image][1] 设置工具栏。
现在列表项不可点击。当使用 ListActivity 列表项是可点击的时,当点击任何项目时,它将打开另一个带有项目标题及其内容的 Activity 。
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Note note = posts.get(position);
Intent intent = new Intent(this, EditNoteActivity.class);
intent.putExtra("noteId", note.getId());
intent.putExtra("noteTitle", note.getTitle());
intent.putExtra("noteContent", note.getContent());
startActivity(intent);
}
最佳答案
这样做
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Note note = posts.get(position);
Intent intent = new Intent(this, EditNoteActivity.class);
intent.putExtra("noteId", note.getId());
intent.putExtra("noteTitle", note.getTitle());
intent.putExtra("noteContent", note.getContent());
startActivity(intent);
}
});
关于android - AppCompatActivity 中的 onlistitemclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37151303/