如何获得单击项目位置与自定义的ListView android系统? [英] How to get clicked item position from Custom ListView in android?

查看:108
本文介绍了如何获得单击项目位置与自定义的ListView android系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让自定义列表视图(由原来的列表中的位置排序之后)的位置。这是因为列表项的数据库ID列表视图项的位置相匹配。所以,我需要得到整理项目的正确位置相匹配的ListView项的位置。我有这个code。

I'm trying to get the position of the custom list view (after sorted from original list position). It is because the database id of the list item matches the position of the listview item. so, i need to get the sorted item's correct position matching the listview item position. I have this code.

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return sampleArrayList.get(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

但I M剔除,我需要得到那个职位进入我的主要活动。任何帮助真的是AP preciated并在此先感谢...

But i m struck out that i need to get that position into my main activity. Any help is really appreciated and thanks in advance...

推荐答案

我怀疑,我完全理解你的问题,你想什么exactly.But我可以建议你,你可以保持HashMap的存储位置ID对每个列表视图

I doubt,I completely understand your problem and what you want exactly.But i can suggest you that you can maintain HashMap for storing position-id pairs for each listview.

在您的CustomAdapter:

in your CustomAdapter:

public static HashMap<Integer,String> myList=new HashMap<Integer,String>();

在getView():

in getView():

String id= (fetch _id from database);
myList.put(position, id);

现在在你的主活性的研究,可以通过投入的onClick这一行()OnItemClickListener()的检索每个列表项的_id:

And now in your main acitivity,you can retrieve _id of each listitem by putting this line in onClick() of OnItemClickListener():

 Long id=Long.parseLong(CustomAdapter.myList.get(position));

这篇关于如何获得单击项目位置与自定义的ListView android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆