Android ListView在单击切换按钮的位置获取TextView值

Android ListView在单击切换按钮的位置获取TextView值,第1张

概述我有以下ListView与自定义列表项:我想从单击ToggleButton的列表项中获取TextView值.这是构建列表的适配器:publicclasssimpleAdapterextendsSimpleAdapter{publicsimpleAdapter(Contextcontext,ArrayList<HashMap<String,String>>list,intreso

我有以下ListVIEw与自定义列表项:

我想从单击Togglebutton的列表项中获取TextVIEw值.

这是构建列表的适配器:

    public class simpleAdapter extends SimpleAdapter {    public simpleAdapter(Context context,            ArrayList<HashMap<String, String>> List, int resource,            String[] from, int[] to) {        super(context, List, resource, from, to);        // Todo auto-generated constructor stub    }    @OverrIDe    public VIEw getVIEw(final int position, VIEw convertVIEw, VIEwGroup parent) {        // Todo auto-generated method stub        // return super.getVIEw(position, convertVIEw, parent);        LayoutInflater inflater = getLayoutInflater();        convertVIEw = inflater.inflate(R.layout.user_campaigns_List_item, parent, false);        tb_campaigns_List_toggle = (Togglebutton) convertVIEw                .findVIEwByID(R.ID.tb_campaigns_List_toggle);        tb_campaigns_List_toggle.setonClickListener(new OnClickListener() {            public voID onClick(VIEw v) {                // Todo auto-generated method stub                Toast.makeText(getApplicationContext(), String.valueOf(position), Toast.LENGTH_SHORT).show();            }        });        return super.getVIEw(position, convertVIEw, parent);    }}

使用此代码,我可以烘焙包含单击的Togglebutton的列表项的位置.
尝试使用此代码获取Text1或ID1值时:

TextVIEw Text1 = (TextVIEw)convertVIEw.findVIEwByID(R.ID.Text1_ID); //this line is outsIDe the onClick(VIEw v) methodString Text1_value = Text1.getText().toString();Toast.makeText(getApplicationContext(), Text1_value, Toast.LENGTH_SHORT).show();

我总是从最后一个ListVIEw项中获取Text1的值.

有任何想法吗?

解决方法:

在ListvIEw的onItemClick函数中,粘贴以下代码:

    VIEw parentVIEw = (VIEw) vIEw.getParent();    textvIEw1 = ((TextVIEw) parentVIEw            .findVIEwByID(R.ID.textvIEw1)).getText().toString();    textvIEw2 = ((TextVIEw) parentVIEw            .findVIEwByID(R.ID.textvIEw2)).getText().toString();    textvIEw3 = ((TextVIEw) parentVIEw            .findVIEwByID(R.ID.textvIEw3)).getText().toString();

您可以使用上面的代码获得任何值.

总结

以上是内存溢出为你收集整理的Android ListView在单击切换按钮的位置获取TextView值全部内容,希望文章能够帮你解决Android ListView在单击切换按钮的位置获取TextView值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1115475.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存