开发者

Check which radioButton was checked IN ANDROID?

开发者 https://www.devze.com 2023-03-29 06:57 出处:网络
i have a radiogroup and when I check anyone in the group I want to know which one was checke开发者_StackOverflow社区d.

i have a radiogroup and when I check anyone in the group I want to know which one was checke开发者_StackOverflow社区d. Can I give each one an id. when I implemented this code


  public void onCheckedChanged(RadioGroup group, int checkedId) {
        mChoice.setText(checkedId+"");
    }

I was getting some random number. I was not able to identify which radiobutton I clicked. Is there anyother way?


You can assign id's like this example from: http://developer.android.com/resources/tutorials/views/hello-formstuff.html#RadioButtons:

<RadioGroup
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">
  <RadioButton android:id="@+id/radio_red"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Red" />
  <RadioButton android:id="@+id/radio_blue"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Blue" />
</RadioGroup>

Then compare checkedId to R.id.radio_red (use whatever you actually assigned it to be though).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号