简体   繁体   English

如何在所有选中的项目中获取作为 ListView 行一部分的 TextView 的值

[英]How to get the value of a TextView that is part of a ListView row in all checked items

在此处输入图片说明

As illustrated in the photo, i have a list view that is made up of a custom layout which has two TextView.如图所示,我有一个列表视图,它由一个自定义布局组成,其中有两个 TextView。 One TextView is for storing numbers which has a visibility of gone, the other is for storing the name, which is visible.一个 TextView 用于存储可见的数字,另一个用于存储可见的名称。

all i want is to be able to get a string of all numbers that are selected when the send button is clicked.我想要的只是能够获得单击发送按钮时选择的所有数字的字符串。

  1. A good suggestion here is to use a recyclerview instead of list view.这里的一个好建议是使用 recyclerview 而不是列表视图。

  2. To achieve want you want with a list view you just set an item click listener to your list view in your activity.要通过列表视图实现您想要的,您只需在您的活动中为列表视图设置一个项目点击侦听器。 The item click listener will pass the View which is the current cell in the list view.项目单击侦听器将传递视图,它是列表视图中的当前单元格。 Then you can find textview by id to locate.然后你可以通过id找到textview来定位。 The Textview ID is set in the layout xml. Textview ID 在布局 xml 中设置。

Example例子

listView.setOnItemClickListener(new OnItemClickListener()
{
    @Override 
    public void onItemClick(AdapterView<?> arg0, View cell,int pos, long arg1)
    { 
        TextView textView = (TextView)cell.findViewByID(R.id.myTextView);
        String texViewContents = textView.getText().toString();
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM