Список с несколькими переключателями в android

Я разрабатываю приложение со списком участников, которые участвуют в разных мероприятиях.

Группа людей, участвующих в группе Игр. Но один человек может участвовать только в одной игре. Итак, я выбрал RadioButton. Четыре игры, а именно A, B, C и D. Список людей представлен в списке с четырьмя RadioButton, нам нужно выбрать по одной среди них для каждого человека.

введите описание изображения здесь

Я пробовал GridView с настраиваемыми данными строки, как показано ниже ...

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

И My Grid List - это один столбец со следующими данными в 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..

Дайте мне любое предложение по выполнению этого процесса ..!


person MGR    schedule 26.03.2013    source источник
comment
«не удалось получить данные» ... какие данные вы хотели бы получить?   -  person R9J    schedule 26.03.2013
comment
Необходимо отобразить поле row.xml в списке GridView ...   -  person MGR    schedule 26.03.2013
comment
Почему бы вам не использовать listview вместо gridview? какая-то конкретная причина?   -  person kumar_android    schedule 26.03.2013
comment
Можем ли мы использовать представление списка с переключателями, как я хочу?   -  person MGR    schedule 26.03.2013
comment
я думаю, что вы сделали что-то не так в своем java-коде ... опубликуйте его тоже, тогда мы сможем выяснить проблему   -  person R9J    schedule 26.03.2013
comment
stackoverflow.com/questions/11625990/, я так ожидал   -  person MGR    schedule 26.03.2013


Ответы (2)


В этом случае вам понадобится специальный ListView. сделайте свой код, как показано ниже, чтобы добиться этого ..

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);

Надеюсь, это поможет :)

person R9J    schedule 26.03.2013
comment
Можем ли мы получить вот так? majgowrishankar.blogspot.in/2013/03/ - person MGR; 27.03.2013

Используйте это в своей RadioGroup, чтобы сделать кликабельным

android: focusable = false

android: focusableInTouchMode = false

person kumar_android    schedule 26.03.2013