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.
-
You definitely can do that in your adapter implementation. Could you show us your ListView and Adapter codes ? – Ye Lin Aung Jul 07 '15 at 03:27
-
hey its not letting me post everything its more than the max lines. cna you give me an example of how i can do it in the adapter implementation? thank you – Mushahid Nawaz Khan Jul 07 '15 at 03:40
-
Try to post your in pastebin.com and upload the link here so that we can see your implementation. – Prokash Sarkar Jul 07 '15 at 03:44
3 Answers
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
}
}

- 11
- 4
-
wouldnt the view.findviewbyid... get null if the row is not visible? – Mushahid Nawaz Khan Jul 07 '15 at 04:08
-
here is the link http://pastebin.com/iRvhUEud and the part i am concerned about starts at tellOthers.setOnClickListener(new View.OnClickListener() { – Mushahid Nawaz Khan Jul 07 '15 at 04:11
-
@MushahidNawazKhan no, it is null if view is null or id is not exits on view. – Lãng Tử Bị Điên Jul 07 '15 at 04:19
-
but the rows that are not visible would be null right? in that case when i select the radio button and click on submit, the rows afte the second one will be null right? – Mushahid Nawaz Khan Jul 07 '15 at 04:28
-
no, it is not null. You can read docutments here http://developer.android.com/reference/android/view/ViewGroup.html#getChildAt(int) – Lãng Tử Bị Điên Jul 07 '15 at 04:29
-
i am getting null when i run the code. i have almost the samethign as the one u posted. I read online some where that the rows that are not visible are null – Mushahid Nawaz Khan Jul 07 '15 at 04:31
-
U can see this link :). http://stackoverflow.com/questions/24811536/android-listview-get-item-view-by-position – Lãng Tử Bị Điên Jul 07 '15 at 09:41
-
You can use custom list view to show your list items with checkbox & textview.

- 804
- 1
- 9
- 23
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 TextView
s
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!

- 826
- 2
- 15
- 34