android-radiobutton

Set selected index of an Android RadioGroup

只谈情不闲聊 提交于 2019-12-31 10:57:06
问题 Is there a way to set the selected index of a RadioGroup in android, other than looping through the child radiobuttons and selecting checking the radio button at the selected index? Note: I am populating the Radio Button Group at run time. 回答1: If your radio group is defined in a layout xml file, each button can be assigned an id. Then you just check a button like this radioGroup.check(R.id.myButtonId); If you created your radio group programmatically (I'm not even sure how you do this...),

How to save RadioButton status with SharedPreference?

两盒软妹~` 提交于 2019-12-25 09:26:05
问题 This is the app view: and here is my activity code: public class Quiz extends AppCompatActivity { public static int point; public static int i = 0; RadioGroup radioGroup; public static int totalPoint =0; int arrValues[]={0,0,0,0}; int iPosition=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz); i = 0; final RadioButton radioButton1 =(RadioButton) findViewById(R.id.number_1); final RadioButton

Saving selected RadioButton's text in model class from recyclerview item

隐身守侯 提交于 2019-12-25 00:13:05
问题 From RecyclerView item, I am trying to save the selected RadioButton's text in model class. When I select a RadioButton from 1st item, it's text is saved appropriately. Problem is, RadioButton's text at the same position from 8th item is also auto saved. If I select radio button from 2nd item, text from 9th item is also auto saved, and so on. How to solve this problem? onBindViewHolder method is given below : @Override public void onBindViewHolder(@NonNull final ViewHolder holder, final int

How to set values for Radio button in android?

[亡魂溺海] 提交于 2019-12-24 14:36:09
问题 I am getting the value from DB and setting it to the respective button in the below format. Is there any optimised way to do the same. All these radio buttons are inside a radio group. if (bundlevalue.get(3).equalsIgnoreCase("Mr.")) { rg_nametitle.check(R.id.mr); } else if (bundlevalue.get(3).equalsIgnoreCase("Mrs.")) { rg_nametitle.check(R.id.mrs); } else if (bundlevalue.get(3).equalsIgnoreCase("Ms.")) { rg_nametitle.check(R.id.ms); } else { rg_nametitle.check(R.id.messrs); } 回答1: You can

Change background for radio button programatically

孤街浪徒 提交于 2019-12-24 09:44:13
问题 I have a RadioGroup with two RadioButtons. I want to change the color of them programmatically when they are disabled. <RadioGroup android:id="@+id/radio_group_transfer" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="22dp" android:layout_marginTop="4dp" android:gravity="center_vertical" android:layoutDirection="ltr" android:orientation="horizontal"> <RadioButton android:id="@+id/national_id_docs" android:layout_width="match_parent"

Creating android RadioGroup with multiple RadioButton (Custom RadioGroup)

爷,独闯天下 提交于 2019-12-23 01:46:24
问题 I want to achieve Single RadioGroup like below image for blood group selection. How can this be done? 回答1: I created my own RadioGridLayout which include RadioGroup code and extends GridLayout. You can copy this code. For me working well. After you can use this layout in your xml and customize like grid layout. For R.styleable.RadioGridLayout_checked I used code like this: <resources> <declare-styleable name="RadioGridLayout"> <attr name="checked" format="integer" /> </declare-styleable> <

Radio group in table layout with radio buttons aligned to columns

我的梦境 提交于 2019-12-22 18:33:09
问题 I am developing a feedback application which should has similar layout to this screen. [1]: https://i.stack.imgur.com/xn3kh.jpg I have designed the xml for layout. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000" android:orientation="vertical" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context="com

How to get id of selected radio button in a radio group

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 11:52:47
问题 I am making a quiz app in which I have a viewPager which has 15 pages in it having 1 question each and a submit button at the last page.Now I want to get the Maximum number of option selected among 15 questions. Below is my code QuestionPagerFragment.java: public class QuestionPagerFragment extends Fragment { protected View mView; String pageData[]; //Stores the text to swipe. String optionData[];//Stores the option data. int rid; RadioGroup group; String ans; String ans1; String ans2;

Radio Button is only partially checked

大憨熊 提交于 2019-12-18 05:41:51
问题 I know this sound weird so here is the picture. It hold the correct value. The correct radiobutton is (partially) selected. All logic in the OnCheckedChangeListener is executed correctly. I'm completly stunned. Why is the radio button not fully checked? Only thing I can think of is that i'm using Rx2Firebase periodRetriever = FirebaseHelper.getInstance(getContext()).getPeriod() .defaultIfEmpty(0) .distinctUntilChanged() .subscribe(new Consumer<Integer>() { @Override public void accept(

How to change background color/shape of a Radiobutton when selected/deselected

送分小仙女□ 提交于 2019-12-14 04:18:07
问题 I am adding radiobuttons programatically to a RadioGroup in a for loop. I want my buttons to have a certain background color when not checked, and another when they are checked (only one can be selected at once). My problem is that I also want this background to be a rounded rectangle. I have it working partially, but whenever I select an answer, it will set that button's background to white, but it won't reset any of the other buttons. I understand that I need some type of selector object,