Skip to content Skip to sidebar Skip to footer

How Do A Custom Listview Item With A Radiobutton And Single Choice

I have this layout for the listview item:

Solution 1:

its worked for me

Step 1:

in Custom Adapter file just declare this

int selectedIndex = -1;

Step 2:Single Row Custom Layout

   <RadioButton
    android:id="@+id/radio_list"
    android:checked="false"
    android:focusable="false"
    android:clickable="false" />

Step 3:

  <ListView
            android:id="@+id/liststorecard"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            **android:descendantFocusability="beforeDescendants"
            android:choiceMode="singleChoice"**
            android:layout_weight="1"
          />

Step 4: Create Interface in Custom Adapter

publicvoidsetSelectedIndex(int index){
        selectedIndex = index;
    }

Step 5: In getview method write code

if(selectedIndex == position)
   {
    holder.rblist.setChecked(true);
   }
  else
   {
    holder.rblist.setChecked(false);
   }

Step 6: final step set Selected Index to interface

liststorecard.setOnItemClickListener(newAdapterView.OnItemClickListener() {
            @OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position, long id) {


                storeCardAdapter.setSelectedIndex(position);
                storeCardAdapter.notifyDataSetChanged();

            }
        });

Solution 2:

you can get your solution by following idea

http://www.androidpeople.com/android-custom-listview-tutorial-part-1

you must have to write your custom adapter for your CustomListView.Hope this will work for you Enjoy

Post a Comment for "How Do A Custom Listview Item With A Radiobutton And Single Choice"