Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

RadioButton RadioGroup Java Android example

RadioButton RadioGroup Android example source code for Android developer
Example for *.xml files

       <RadioGroup android:id="@+id/idRadio_group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:orientation="vertical">

            <RadioButton android:id="@+id/idRadio_1"
                android:text="@string/textLabel_1"/>
            <RadioButton android:id="@+id/idRadio_2"
                android:text="@string/textLabel_2"/>
            <RadioButton android:id="@+id/idRadio_3"
                android:text="@string/textLabel_3"/>

        </RadioGroup>



Example for *.java files

// import
import android.widget.RadioGroup;
// get handle of RadioGroup
RadioGroup  mRadioGroup = (RadioGroup) findViewById(R.id.idRadio_group);

// which RadioButton is selected for example in some function body
         int nUnits = 10; // decimetry
    	 int nIdRadio = mRadioGroup.getCheckedRadioButtonId();
    			if(nIdRadio == R.id.idRadio_1) nUnits = 1; // metr
    			else if(nIdRadio == R.id.idRadio_2) nUnits = 10; // decimetr
    			else if(nIdRadio == R.id.idRadio_3) nUnits = 100; // cm
    			else if(nIdRadio == R.id.idRadio_4) nUnits = 1000; // mm


// listener for RadioGroup Java Android example
       mRadioGroup.setOnCheckedChangeListener(
                new RadioGroup.OnCheckedChangeListener() {
                    public void onCheckedChanged(RadioGroup group,
                            int checkedId) {
                        Log.v("Selected", "New radio item selected: " + checkedId);
                        recordNewUIState();
                    }
                });




396LW NO topic_id




AD

Další témata ....(Topics)


298

R cannot be resolved to a variable | r-cannot-be-resolved-to-a-variable


Check your xml files in Eclipse Graphical Editor and fix problems.

android/r-cannot-be-resolved-android.jpg

Check project setup, right click on project, select properties, Java build path and
select correct Android version etc.
android/order-and-export-eclipse-android-project.jpg

Right click on project, Android Tools, Fix Project Properties

Menu Eclipse select Project ->Clean.
221

android - OnClickListener must override a superclass method | android-onclicklistener-must-override-a-superclass-method


The method onClick(DialogInterface, int) of type new DialogInterface.OnClickListener(){} must override a superclass method.

Try this:
Right click on project
Select Properties
In open dialogue select Java compiler
Set Enable project specific settings
Set Compiler compliance level to 1.6

android/project-properties-eclipse.png

android/java-compiler-settings-eclipse.png