android - AppCompatActivity 中的 onlistitemclick

标签 android listview appcompatactivity

我遵循了此 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/

相关文章:

Android ImageButton 背景色

android - 如何在 ListView 中添加顶部项目?

java - 设置列表项被点击时的背景颜色

android - 当您拥有 AppCompatActivity 和标准库时,为什么要包含最低 SDK 版本?

android - 您需要在创建 AlertDialog 时使用 Theme.AppCompat 主题

android - 什么时候应该使用 sp、dp、px、in 和 mm? (安卓)

android - 如何在 Android 中设置字体?

Android googlemap 内存不足

android - 图标未显示在 ImageView 中

android - 为什么我需要按两次后退按钮才能在第一次关闭 fragment ?