RadioButton RadioGroup Java Android example
RadioButton RadioGroup Android example source code for Android developer
Example for *.xml files
Example for *.java files
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)
Warning: The application may be doing too much work on its main thread
Try this sorce code:
Try this sorce code:
import android.os.StrictMode;
public class MyActivity extends Activity {
static{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
@Override
public void onCreate(Bundle savedInstanceState) {
//.................. etc.
Wiktionary - SDK samples Android
about.xml
protected void showAbout() {
// Inflate the about message contents
View messageView = getLayoutInflater().inflate(R.layout.about, null, false);
// When linking text, force to always use default color. This works
// around a pressed color state bug.
TextView textView = (TextView) messageView.findViewById(R.id.about_credits);
int defaultColor = textView.getTextColors().getDefaultColor();
textView.setTextColor(defaultColor);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.app_icon);
builder.setTitle(R.string.app_name);
builder.setView(messageView);
builder.create();
builder.show();
}
about.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
//www.apache.org/licenses/LICENSE-2.0
-->
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dip">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="@string/app_descrip"
android:textColor="?android:attr/textColorPrimaryInverse" />
<TextView
android:id="@+id/about_credits"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dip"
android:textSize="16sp"
android:text="@string/app_credits"
android:autoLink="web"
android:textColor="?android:attr/textColorPrimaryInverse" />
</LinearLayout>
Try insert + before R.drawable.xxxx
// error
InputStream is = context.getResources().openRawResource(R.drawable.app_sample_code);
// ok
InputStream is = context.getResources().openRawResource(+R.drawable.app_sample_code);
Switch statement with numbers and array of strings Java example.
Possible:
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "One", "Two", "Three", "Four" };
int i = 2;
switch (i) {
case 1: {
System.out.println(arrayOfString[i]);
break;
}
case 2: {
System.out.println(arrayOfString[i]);
break;
}
case 3: {
System.out.println(arrayOfString[i]);
break;
}
default: {
System.out.println("Enter a valid value.");
}
} // END of switch
}
}
/*
* Three
*/
Possible:
case 1:
System.out.println(arrayOfString[i]);
break;
// i love this notation
case 1:{
System.out.println(arrayOfString[i]);
}break;
case 1:{
System.out.println(arrayOfString[i]);
break;
}
Try this:
- check names of drawables (file name must contain only abc...xyz 012...789 _ . in Resources folder ,
names have to start with lower case
MyImage.jpg == problem ,
names with space
my image.jpg == problem,
names with -
my-image.png == problem)
- check duplicate names with other extension ( my_image.jpg - my_image.png makes the problem)
- restart Android Studio
- if problem persist:
- check c:\Users\me\AndroidStudioProjects\myProject\myModule\build\intermediates\res\merged\debug\ drawable folder for corupted names or delete ALL drawable folders
- synk projekt, rebuild projekt
- if problem persist:
- restart Android Studio, wait for complete closure of the Android Studio!
- check names of drawables (file name must contain only abc...xyz 012...789 _ . in Resources folder ,
names have to start with lower case
MyImage.jpg == problem ,
names with space
my image.jpg == problem,
names with -
my-image.png == problem)
- check duplicate names with other extension ( my_image.jpg - my_image.png makes the problem)
- restart Android Studio
- if problem persist:
- check c:\Users\me\AndroidStudioProjects\myProject\myModule\build\intermediates\res\merged\debug\ drawable folder for corupted names or delete ALL drawable folders
- synk projekt, rebuild projekt
- if problem persist:
- restart Android Studio, wait for complete closure of the Android Studio!
Editace: 2011-09-26 20:48:27
Počet článků v kategorii: 396
Url:radiobutton-radiogroup-android-example