android - 如何从 android 的 setOnItemClickListener 中的 listview 获取对象?

标签 android android-adapterview

我已经在 arrayadapter 中添加了 arraylist,其中包含对象,每个对象由两个元素/项目组成,我已经成功地为 setListAdapter 设置了该适配器,现在我想在 listview 的 setOnItemClickListener 中获取这些项目。

这是我的代码

   TweetListAdaptor adaptor = new TweetListAdaptor(this,R.layout.list_item, tweets);       
   setListAdapter(adaptor); 
   ListView lv = getListView();
   lv.setTextFilterEnabled(true);
   lv.setOnItemClickListener(new OnItemClickListener() 
   {
   public void onItemClick(AdapterView<?> parent, View view,int position, long id) 
   {
     //here i want to get the items             
   }
 });

最佳答案

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    int color = parent.getAdapter().getItem(position);
}

关于android - 如何从 android 的 setOnItemClickListener 中的 listview 获取对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7073577/

相关文章:

android - 如何在onPictureTaken中旋转和翻转位图

android - 如何在TabLayout中制作移动动画

android - 如何在 Android 4.4 中查找数据库路径(API 级别 : 19)?

android - AdapterView 不支持无法启动 Activity :UnsupportedOperationException: addView(View, LayoutParams)

android - Adapter 和 AdapterView 之间的契约

android - 设置安卓 :windowBackground to @null makes scrolling to smear?

android - Espresso : android. support.test.espresso.AmbiguousViewMatcherException for AdapterView

java - 从打开的子 Activity 转到现有 fragment

android - GridView.setOnItemClickListener 不工作

android - Google Instant App - 如何使用 Appium 实现自动化