Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to keep state of RadioButton in Android?
    primarykey
    data
    text
    <p>Hi I'm trying to develop an application which runs for every interval time, lets say for every 1 minute it will display some <code>Toast message</code>.</p> <p>But problem is I'm using <code>RadioButton</code> functionality is perfect but when I tap on one radio button it will be green, but when I close and re-open the activity I'll get as none of the radio buttons selected.</p> <p>Here is my <code>MainActivity.java</code></p> <pre><code>public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } 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.radio_one_min: if (checked) { //some code } break; case R.id.radio_ten_min: if (checked) { //some code } break; case R.id.radio_disable: if (checked) { //some code } break; } } } </code></pre> <p>and here is my <code>activity_main.xml</code></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/radio"&gt; &lt;RadioButton android:id="@+id/radio_disable" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Disable" android:onClick="onRadioButtonClicked"/&gt; &lt;RadioButton android:id="@+id/radio_one_min" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1 minute" android:onClick="onRadioButtonClicked"/&gt; &lt;RadioButton android:id="@+id/radio_ten_min" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="10 minute" android:onClick="onRadioButtonClicked"/&gt; &lt;/RadioGroup&gt; </code></pre> <p>Please help me to solve this riddle.</p> <p>Thanks in advance...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload