Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

get string of radio button in android

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MyAndroidAppActivity extends Activity {

  private RadioGroup radioGroup;
  private RadioButton radioButton;
  private Button btnDisplay;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    addListenerOnButton();

  }

  public void addListenerOnButton() {

    radioGroup = (RadioGroup) findViewById(R.id.radio);
    btnDisplay = (Button) findViewById(R.id.btnDisplay);

    btnDisplay.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

                // get selected radio button from radioGroup
            int selectedId = radioGroup.getCheckedRadioButtonId();

            // find the radiobutton by returned id
            radioButton = (RadioButton) findViewById(selectedId);

            Toast.makeText(MyAndroidAppActivity.this,
                radioButton.getText(), Toast.LENGTH_SHORT).show();

        }

    });

  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: initialize applet in java 
Java :: java android edit text set value 
Java :: parse object to int java 
Java :: how to find absolute difference in java 
Java :: get the length of an array java 
Java :: java long to double 
Java :: how to print byte array in java 
Java :: how to import class from another file in java 
Java :: current time in long java 
Java :: generating random number 
Java :: arraylist input from user java 
Java :: set textview text android java 
Java :: hello world program in java 
Java :: java printf 
Java :: java convert double to int 
Java :: final finally finalize 
Java :: java print item to text file 
Java :: java make a null string 
Java :: how to use user uid in android 
Java :: change size of array java 
Java :: Java heap retention in BodyContentImpl 
Java :: constraintlayout vs coordinatorlayout 
Java :: java String revers 
Java :: min in java 
Java :: bytearrayoutputstream 
Java :: is java compiled or interpreted 
Java :: What is the way to use profiles to configure the environment-specific configuration with Spring Boot? 
Java :: string to int error 
Java :: important features of java programming language 
Java :: java singleton 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =