Android Manifestxml

This section contains the full code of the current AndroidViews' AndroidManifest.xml. If you are following along in Eclipse, modify your Activity's AndroidManifest.xml to look as follows:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android=http://schemas.android.com/apk/res/android package="android_programmers_guide.AndroidViews"> <application android:icon="@drawable/icon"> <activity android:name=".AndroidViews"

android:label="@string/app_name"> <intent-filter>

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

<activity android:name=".AutoComplete" android:label="AutoComplete"> <intent-filter>

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>

<activity android:name=".testButton" android:label="TestButton"> <intent-filter>

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>

<activity android:name=".testCheckBox" android:label="TestCheckBox"> <intent-filter>

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>

<activity android:name=".testEditText" android:label="TestEditText"> <intent-filter>

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>

This section shows the complete code of the radiogroup.xml. Create a new XML file in your project named radiogroup.xml using the instructions outlined earlier in this chapter. Use the following code to model your file.

<activity android:name=".testRadioGroup" android:label="Test

RadioGroup">

<intent-filter>

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter>

</activity> </application> </manifest>

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

ii ii

<RadioGroup android:id="@+id/testRadioGroup android:layout_width="fill_parent" android:layout_height="wrap_content" >

ii ii ii

<RadioButton android:text="Radio 1"

<RadioButton android:text="Radio 2" android:id="@+id/radio2" />

</RadioGroup> <Button android:id="@+id/enableButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Set isEnabled"/>

<Button android:id="@+id/backgroundColorButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Change Background Color"/> </LinearLayout>

This section covers the final file needed to implement your RadioGroup Activity. Create a new .java file in your project named testRadioGroup.java. This file is the main file of the Activity and contains the actionable code. Use the following code in your testRadioGroup.java to finish this Activity.

package android_programmers_guide.AndroidViews;

import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.RadioGroup; import android.widget.Button; import android.graphics.Color;

public class testRadioGroup extends Activity { @Override public void onCreate(Bundle icicle) {

super.onCreate(icicle); setContentView(R.layout.radiogroup);

final RadioGroup radiogroup = (RadioGroup) findViewById(R.id.testRadioGroup);

final Button changeButton = (Button)findViewByld(R.id.enableButton); changeButton.setOnClickListener(new Button.OnClickListener() { public void onClick(View v){

changeOption(radiogroup); }

final Button changeButton2 = (Button) findViewById(R.id.backgroundColorButton);

changeButton2.setOnClickListener(new Button.OnClickListener() { public void onClick(View v){

changeOption2(radiogroup);

public void changeOption(RadioGroup radiogroup){ if (radiogroup.isEnabled()){

radiogroup.setEnabled(false);

else{

radiogroup.setEnabled(true);

public void changeOption2(RadioGroup radiogroup){ radiogroup.setBackgroundColor(Color.RED);

0 0

Post a comment