Thursday, January 20, 2011

[android-developers] Re: Radiogroup adding a radio button in listview

Bear in mind that when you're using a ListView, not all your item
views are created and visible at the same time. You are creating or
modifying the visible view on demand based on what is visible at the
moment.

If you want decide if a radio button in a ListView should be active or
inactive at any moment, you need to store that in some structure
accessible to the adapter so that when you create or update the list
item view, you can enable or disable the button appropriately. The
radio button group as a whole isn't going to help you precisely
because not all the buttons are visible and active at the same time so
they can't all be toggled automatically. I know this sounds
complicated but that's just how ListView is optimized to handle an
arbitrarily large number of items. You might be better off just using
a ScrollView if your list of items is not prohibitively long.

Doug

On Jan 20, 11:13 am, kiros88 <ghui...@gmail.com> wrote:
> Hi so basically im trying to have a list in extends ListActivity and
> stuff but right now im trying to get a listview of radio buttons which
> i guess works but now im trying to apply a radio group for the list.
> This is the part im stuck on so basically
>
> once i created my own array adapter i wanted to make in the getView
> function every added View(which is radiobutton) to go into the array
> adapter add to my radio group
>
> public View getView(int position, View convertView, ViewGroup parent)
> {
>                  // TODO Auto-generated method stub
>                  //return super.getView(position, convertView, parent);
>
>                  LayoutInflater inflater=getLayoutInflater();
>                  View row=inflater.inflate(R.layout.radio, parent, false);
>                  //CheckedTextView
> label=(CheckedTextView)row.findViewById(R.id.text1);
>                  RadioButton label =
> (RadioButton)row.findViewById(R.id.RadioButton01);
>                  mRadioGroup.addView(label, position, layoutParams);
>                  label.setText(zones.get(position));
>
>                  return row;
>
> my layout radio.xml just has a
>
> radiogroup
> radiobutton inside radiogroup
>
> so the only line that doesnt work is the call to add view in
> mRadioGroup

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate