简体   繁体   中英

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. One TextView is for storing numbers which has a visibility of gone, the other is for storing the name, which is visible.

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.

  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. The Textview ID is set in the layout 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();
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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