从列表视图中单击列表项时,将自定义列表项内容传递给新活动 [英] Pass custom list item content to new activity when list item is clicked from a listview

查看:66
本文介绍了从列表视图中单击列表项时,将自定义列表项内容传递给新活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想知道是否有可能.本质上,我有一个列表视图,该列表视图通过编程方式填充了自定义列表项视图和自定义适配器.这就像一个符咒,但是问题在于,一旦填充此列表,我就必须以特定的方式对该列表进行排序.放入列表中的值存储在String数组中.问题是,当我对列表视图进行排序时,它会更改我认为将存储值的位置的索引.我想使用在列表视图中找到的某些值来启动新活动.这可能吗?我可以从列表项中提取一个字符串,然后在单击该项目时在存储值的数组中查找它.然后,我可以使用Extras启动新的意图,以便可以将新数据传递给新活动.那么,是否可以从列表项中提取字符串?

First of all I want to know if this is possible. Essentially I have a listview that is being populated programatically with a custom list item view and a custom adapter. This works like a charm but the problem is that I have to sort this list in a specific way once it is populated. The values that are being put into the list are stored in String arrays. The problem is that when I sort the listview it changes the index of where I thought the values would be stored. I want to start a new activity with certain values found in the list view. Is this possible? I could take a string from the list item and can look it up in my arrays storing the values when that item is clicked. I can then start a new intent with extras so that I can pass this new data to the new activity. So, is it possible to extract a string from a list item?

推荐答案

lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3){

    Object o=lv.getItemAtPosition(position);

    UtilityClass u=(UtilityClass)o;
    String s=u.getMyData();
    Intent edit = new Intent(context, AnotherActivity.class);           
                        edit.putExtra("your_identifier", Integer.toString(position));
    startActivity(intent);


        }});

这篇关于从列表视图中单击列表项时,将自定义列表项内容传递给新活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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