1

In android, is it possible to get all items inside the list view. Lets say the list view has multiple rows and only 2 rows are visible on the screen while the rest are accessible using the scroll bar. Each row has a radio button and a text view. Is there a way to get all textview of the rows whose radio button is selected and not just the ones visible on the screen.

3 Answers3

0

Your answer may be:

for(int item = 0; item < m_listitem.count(); item ++){
            if(m_listitem[item].isSelected){
                View view = ListView.getChildAt(i);
                TextView textview = view.findViewById(your textView id);
                // do some thing
            }
        }
0

You can use custom list view to show your list items with checkbox & textview.

Ashish Jaiswal
  • 704
  • 1
  • 8
  • 22
0

I happened to have a similar requirement where I had multiple EditText inside a ListView and only few of them were visible on the screen. I needed to get the values of all EditText and not just the ones visible on the screen.

Well if you are using a default Adapter, then the way it will work is it will recycle the old views to create new ones. So there is no way to preserve values of those Views which are not visible. So the only workaround is to create your own Adapter, maybe something like the following, which will not recycle any views, but every time inflate new ones.

public class ListViewAdapter extends ArrayAdapter {

    public ListViewAdapter(Context context, ArrayList<Object> items) {
        super(context, 0, items);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return LayoutInflater.from(getContext()).inflate(R.layout.your_layout_for_list_view_item, parent, false);
    }
}

After that, as in above answer Lãng Tử Bị Điên has mentioned, you can check in your java code, if your radio buttons are checked or not, and according to that, selected desired TextViews

for(int item = 0; item < m_listitem.count(); item ++){
        if(m_listitem[item].isSelected){
            View view = ListView.getChildAt(i);
            TextView textview = view.findViewById(your textView id);
            // do some thing
        }
    }

Hopefully this should do it.. It sure worked in my case!

Vijay Chavda
  • 766
  • 2
  • 11
  • 29