2

In My application, i'm developing an application Student Ranking system.

Here, is the link which i asked earlier. Now my requirement have filled but i couldn't access the data in it..

public class ListMobileActivity extends ListActivity {
static final String[] MOBILE_OS = new String[] { "001 AAAA", "002 BBBB",
        "003 CCCC", "004 DDDD"};
static final String[] MOBILE_OS1 = new String[] { "AAAA", "BBBB",
    "CCCC", "DDDD"};
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //setListAdapter(new ArrayAdapter<String>(this, R.layout.list_mobile,
    //      R.id.label, MOBILE_OS));

    setListAdapter(new MobileArrayAdapter(this, MOBILE_OS));
}

}

and Adapter is,..

public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;

public MobileArrayAdapter(Context context, String[] values) {
    super(context, R.layout.list_mobile, values);
    this.context = context;
    this.values = values;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.list_mobile, parent, false);
    TextView textView = (TextView) rowView.findViewById(R.id.label1);
    TextView textView1 = (TextView) rowView.findViewById(R.id.label);
    RadioGroup radioSexGroup=(RadioGroup) rowView.findViewById(R.id.radioSex);
    int selectedId = radioSexGroup.getCheckedRadioButtonId();
    RadioButton radioSexButton= (RadioButton) rowView.findViewById(selectedId);;
    textView.setText(values[position]);
    textView1.setText(String.valueOf(position+1));
    // Change icon based on name
    String s = values[position];
    System.out.println(s);
    return rowView;
}
}

I could perform any action on this Radio Buttons..

Now my output screen is as follow...

enter image description here

But i couldn't get which radio button is selected on each row with particular student, help me to achieve this. Am i need to change the Adapter using...

Community
  • 1
  • 1

2 Answers2

0

Use array list to save selection

List<Integer> sexGrp=new ArrayList<Integer>();

Use this listener in adapter

radioSexGroup.setTag(position);
                radioSexGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() 
                {
                    public void onCheckedChanged(RadioGroup group, int checkedId) {
                        sexGrp.add(Integer.parseInt(group.getTag().toString()), checkedId);

                    }
                });
Arun C
  • 9,035
  • 2
  • 28
  • 42
0

Write this loop in your getView method , here arrayChekedCheckBox is collection of your all checked checkbox

        for (int i = 0; i < arrayListOfStudent.size(); i++) {
            if (i==postion){
                arrayChekedCheckBox.add(postion) ;
                break;
            }
        }
dharmendra
  • 7,835
  • 5
  • 38
  • 71