1

I'm developing an application with the list of member who participating in different events.

A group of people participating in a group of Games. But one person can participate in only one game. So i have chosen the RadioButton. Four Games namely A,B,C and D. The list of People have listed in a list with four RadioButton, we need to select one among them for each people.

enter image description here

I Have tried GridView with customized row data as follow...

<GridView
        android:id="@+id/gridViewMarkList"
        android:layout_width="match_parent"
        android:layout_height="326dp"
        android:numColumns="1" >
</GridView>

And My Grid List is a Single column with the following data in row.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="500dp"
android:layout_height="fill_parent"
android:padding="10dp" >

<TableRow>

    <TextView
        android:id="@+id/SNo"
        style="@style/text"
        android:layout_width="100dp"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/Name"
        style="@style/text"
        android:layout_width="180dp"
        android:layout_height="wrap_content" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="160dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/A"
            android:layout_width="40dp"
            android:layout_height="wrap_content"
            android:checked="true" />

        <RadioButton
            android:id="@+id/B"
            android:layout_width="40dp"
            android:layout_height="wrap_content" />

        <RadioButton
            android:id="@+id/C"
            android:layout_width="40dp"
            android:layout_height="wrap_content" />

        <RadioButton
            android:id="@+id/D"
            android:layout_width="40dp"
            android:layout_height="wrap_content" />
    </RadioGroup>
</TableRow>

Now i couldn't retrieve the Data in the Activity..

Give me any suggestion for doing this Process..!

MGR
  • 382
  • 2
  • 7
  • 21

2 Answers2

1

You will need a custom ListView for this case. make your code like below to achieve it..

row.xml

<?xml version="1.0" encoding="utf-8"?>    
<RelativeLayout>

<TextView
    android:id="@+id/SNo"
    style="@style/text"
    android:layout_width="100dp"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/Name"
    style="@style/text"
    android:layout_width="180dp"
    android:layout_height="wrap_content" />

<RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="160dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/A"
        android:layout_width="40dp"
        android:layout_height="wrap_content"
        android:checked="true" />

    <RadioButton
        android:id="@+id/B"
        android:layout_width="40dp"
        android:layout_height="wrap_content" />

    <RadioButton
        android:id="@+id/C"
        android:layout_width="40dp"
        android:layout_height="wrap_content" />

    <RadioButton
        android:id="@+id/D"
        android:layout_width="40dp"
        android:layout_height="wrap_content" />
</RadioGroup>

CustomListAdapter.java

public class CustomListAdapter extends ArrayAdapter<String> {

private Context mContext = null;
private int id;
private List<String> list = null;

public CustomListAdapter(Context context, int textViewResourceId, List<String> list) {

    super(context, textViewResourceId, patientNameList);
    mContext = context;
    id = textViewResourceId;
    this.list = list;
}

@Override
public View getView(int position, View v, ViewGroup parent) {
    View mView = v;
    if (mView == null) {
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(id, null);
    }


    /* 
        here you go with your views which you gonna display
        ex. : RadioButton gameOption = (RadioButton) mView.findViewById(R.id.gameOptionRadioBtn);
     */


    return mView;
}

}

InYourActivityClass

ArrayAdapter<String> adapter = new CustomListAdapter(this, R.layout.row, list);
listView.setAdapter(adapter);

Hope this will help:)

R9J
  • 6,605
  • 4
  • 19
  • 25
  • Can we get Like this? http://majgowrishankar.blogspot.in/2013/03/android-listview-with-radiogroup.html – MGR Mar 27 '13 at 06:04
0

Use this in your RadioGroup to make clickable

android:focusable="false"

android:focusableInTouchMode="false"

Community
  • 1
  • 1
kumar_android
  • 2,273
  • 1
  • 21
  • 30