-2

I have a listview and a associated row view(xml) for it, There are 5 questions in the list and and each question has 4 options. So the row view xml has defined text view (for question) and 4 unique radio buttons inside radio group (for options),so a single text view as a question with 4 options is a single component that is repeated 5 times in a list. My problem is how can one retrieve the particular radio button selected for all the 5 questions and their associated options on a single event for eg: Submit Button

Stuck up with a serious problem, Help Appreciated

userDK
  • 13
  • 1
  • 4
  • You have to Look in to this and get idea : http://dj-android.blogspot.in/2013/02/multi-selection-listview-android-with.html – Dhaval Parmar Mar 21 '13 at 07:29

2 Answers2

0
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();

// Check which radio button was clicked
switch(view.getId()) {
    case R.id.radiobutton1:
        if (checked)
            // radio button 1 is selected.
        break;
    case R.id.radiobutton2:
        if (checked)
            // radio button 2 is selected.
        break;
     case R.id.radiobutton3:
        if (checked)
            // radio button 3 is selected.
        break;
      case R.id.radiobutton4:
        if (checked)
            // radio button 4 is selected.
        break;
  }
}

http://developer.android.com/guide/topics/ui/controls/radiobutton.

public View getView(final int arg0, View arg1, ViewGroup arg2) {
    final ViewHolder vh;
    vh= new ViewHolder();

    if(arg1==null )
     {
        arg1=mInflater.inflate(R.layout.listviewsingleimg, arg2,false);
        vh.iv1= (ImageView)arg1.findViewById(R.id.ivs);
        vh.rb= (RadioButton) arg1.findViewById(R.id.radioButton1);
        vh.tv= (TextView)arg1.findViewById(R.id.textView1);

     }
    else
    {
     arg1.setTag(vh);
    }
        vh.iv1.setImageResource(R.drawable.ic_launcher);
        vh.tv.setText("hello");
        vh.rb.setText("radioButton");
        vh.rb.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(arg0==1)
                {
                switch(v.getId()) {
                case R.id.radioButton1:
                    if (vh.rb.isChecked())
                        // radio button 1 is selected.
                        Toast.makeText(c,"radiobutton 1 clicked",1000).show();
                    break;
                }
              }

            }

        });


    return arg1;
}

static class ViewHolder
{
TextView tv;
RadioButton rb;
ImageView iv1;

}

The above displays toast when radiobutton in position 1 of listview is clicked.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • This will work for them, but how can u make them unique with the appropriate list item? For eg: on all the position of the list view the same event will be triggered, i wanna make first radio button unique to the first position and again the first radio button unique to the second list position. – userDK Mar 21 '13 at 08:44
  • you can use the position to check which radio button is clicked in listview. – Raghunandan Mar 21 '13 at 08:48
  • can you please provide sample code? – userDK Mar 21 '13 at 08:54
0

Hello my friend i got your question

you will have to use sparseBooleanArray for getting the radio button c staus of all five question on button click

j0k
  • 22,600
  • 28
  • 79
  • 90
Bhushan Shirsath
  • 258
  • 3
  • 12