Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:46:01+00:00 2026-06-14T19:46:01+00:00

I’m trying to start programming an android 2.1 / Java app by (piece by

  • 0

I’m trying to start programming an android 2.1 / Java app by (piece by piece) copying (and slightly modifying) a specific code-sample from the Android 2.1 sdk : C:\Program Files\Java\android-2.1_r03-windows\samples\android-7\ApiDemos\src\com\example\android\apis\view\RadioGroup1.java

The RadioButtons can be selected and as a result the other radiobuttons in the group are deselected. So far so good. But unlike in the original program clicking on Clear (‘C’) does nothing and the ‘selected’ TextView doesn’t show the selected id. The initial text ‘You have selected: (none)’ (modified to ‘C:-‘) is shown and is not updated after clicking on one of the radiobuttons).

Can anyone tell what’s wrong / where to proceed?

I also modified / partially copied / added several .xml files in the process: AndroidManifest.xml, layout/activity_main.xml, values/drawables.xml, values/ids.xml, values/strings.xml, values/styles.xml, drawable/filled_box.xml (and added some .png files in the drawable directories). android-support-v4.jar is in the project’s lib directory for backward compatibility (target 15, minimum 7).

Here’s RadioGroup1.java:

package nl.computerhuys.simplescore;

import nl.computerhuys.simplescore.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.RadioGroup;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.LinearLayout;


public class RadioGroup1 extends Activity implements RadioGroup.OnCheckedChangeListener,
        View.OnClickListener {

    private TextView mChoice;
    private RadioGroup mRadioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        mRadioGroup = (RadioGroup) findViewById(R.id.menu);

        // test adding a radio button programmatically
        RadioButton newRadioButton = new RadioButton(this);
        newRadioButton.setText(R.string.radio_group_s1);
        newRadioButton.setId(R.id.s1);
        LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
                RadioGroup.LayoutParams.WRAP_CONTENT,
                RadioGroup.LayoutParams.WRAP_CONTENT);
        mRadioGroup.addView(newRadioButton, 0, layoutParams);

        // test listening to checked change events
        String selection = getString(R.string.radio_group_selection);
        mRadioGroup.setOnCheckedChangeListener(this);
        mChoice = (TextView) findViewById(R.id.choice);
        mChoice.setText(selection + mRadioGroup.getCheckedRadioButtonId());

        // test clearing the selection
        Button clearButton = (Button) findViewById(R.id.clear);
        clearButton.setOnClickListener(this);
    }

    public void onCheckedChanged(RadioGroup group, int checkedId) {
        String selection = getString(R.string.radio_group_selection);
        String none = getString(R.string.radio_group_none);
        mChoice.setText(selection +
                (checkedId == View.NO_ID ? none : checkedId));
    }

    public void onClick(View v) {
        mRadioGroup.clearCheck();
    }
}

Here’s MainActivity.java:

package nl.computerhuys.simplescore;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

Here’s activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android1:background="@drawable/screen_background_black"
    tools:context=".MainActivity" >

    <RadioGroup
        android:id="@+id/menu"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:checkedButton="@+id/s1"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/s1"
            android:text="@string/radio_group_1_s1" />

        <RadioButton
            android:id="@+id/s2"
            android:text="@string/radio_group_1_s2" />

        <RadioButton
            android:id="@+id/s3"
            android:text="@string/radio_group_1_s3" />

        <TextView
            android:id="@+id/choice"
            android:text="@string/radio_group_1_selection" />

        <Button
            android1:id="@+id/clear"
            android1:layout_width="wrap_content"
            android1:layout_height="wrap_content"
            android1:text="@string/radio_group_1_clear" />

    </RadioGroup>

</RelativeLayout>

and AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="nl.computerhuys.simplescore"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <uses-library android:name="nl.computerhuys.mylibrary" android:required="false" />

        <activity
            android:name="nl.computerhuys.simplescore.MainActivity"
            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="view.RadioGroup1" android:label="Views/Radio Group" android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>

    </application>

</manifest>

logCat file after modifications (can’t find out how to post that other than by editing the original post:(

09-16 16:18:01.377: D/AndroidRuntime(1476): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
09-16 16:18:01.377: D/AndroidRuntime(1476): CheckJNI is ON
09-16 16:18:01.884: D/AndroidRuntime(1476): --- registering native functions ---
09-16 16:18:02.714: D/ddm-heap(1476): Got feature list request
09-16 16:18:03.804: D/PackageParser(412): Scanning package: /data/app/vmdl47668.tmp
09-16 16:18:04.514: I/PackageManager(412): Removing non-system package:nl.computerhuys.simplescore
09-16 16:18:04.524: D/PackageManager(412): Removing package nl.computerhuys.simplescore
09-16 16:18:04.534: D/PackageManager(412):   Activities: nl.computerhuys.simplescore.MainActivity
09-16 16:18:04.784: D/PackageManager(412): Scanning package nl.computerhuys.simplescore
09-16 16:18:04.795: I/PackageManager(412): /data/app/vmdl47668.tmp changed; unpacking
09-16 16:18:04.826: D/installd(31): DexInv: --- BEGIN '/data/app/vmdl47668.tmp' ---
09-16 16:18:07.805: D/dalvikvm(1482): DexOpt: load 365ms, verify 1635ms, opt 71ms
09-16 16:18:08.005: D/installd(31): DexInv: --- END '/data/app/vmdl47668.tmp' (success) ---
09-16 16:18:08.005: D/PackageManager(412):   Activities: nl.computerhuys.simplescore.MainActivity
09-16 16:18:08.025: D/ActivityManager(412): Uninstalling process nl.computerhuys.simplescore
09-16 16:18:08.035: D/ActivityManager(412): Force removing process ProcessRecord{44f15ef0 1468:nl.computerhuys.simplescore/10028} (nl.computerhuys.simplescore/10028)
09-16 16:18:08.055: I/Process(412): Sending signal. PID: 1468 SIG: 9
09-16 16:18:08.195: I/UsageStats(412): Unexpected resume of com.android.launcher while already resumed in nl.computerhuys.simplescore
09-16 16:18:08.295: I/WindowManager(412): WIN DEATH: Window{44d60a30 nl.computerhuys.simplescore/nl.computerhuys.simplescore.MainActivity paused=false}
09-16 16:18:08.435: D/ActivityManager(412): Received spurious death notification for thread android.os.BinderProxy@44d89e10
09-16 16:18:08.795: W/InputManagerService(412): Got RemoteException sending setActive(false) notification to pid 1468 uid 10028
09-16 16:18:09.787: I/installd(31): move /data/dalvik-cache/data@app@vmdl47668.tmp@classes.dex -> /data/dalvik-cache/data@app@nl.computerhuys.simplescore.apk@classes.dex
09-16 16:18:09.825: D/PackageManager(412): New package installed in /data/app/nl.computerhuys.simplescore.apk
09-16 16:18:10.075: D/AndroidRuntime(1476): Shutting down VM
09-16 16:18:10.085: D/dalvikvm(1476): DestroyJavaVM waiting for non-daemon threads to exit
09-16 16:18:10.104: D/dalvikvm(1476): DestroyJavaVM shutting VM down
09-16 16:18:10.104: D/dalvikvm(1476): HeapWorker thread shutting down
09-16 16:18:10.104: D/dalvikvm(1476): HeapWorker thread has shut down
09-16 16:18:10.104: D/jdwp(1476): JDWP shutting down net...
09-16 16:18:10.115: I/dalvikvm(1476): Debugger has detached; object registry had 1 entries
09-16 16:18:10.128: D/dalvikvm(1476): VM cleaning up
09-16 16:18:10.155: E/AndroidRuntime(1476): ERROR: thread attach failed
09-16 16:18:10.187: D/ActivityManager(412): Uninstalling process nl.computerhuys.simplescore
09-16 16:18:10.225: D/dalvikvm(1476): LinearAlloc 0x0 used 623916 of 5242880 (11%)
09-16 16:18:11.376: D/dalvikvm(412): GC freed 9687 objects / 641216 bytes in 666ms
09-16 16:18:11.414: W/ResourceType(412): Resources don't contain package for resource number 0x7f0700e5
09-16 16:18:11.425: W/ResourceType(412): Resources don't contain package for resource number 0x7f020031
09-16 16:18:11.425: W/ResourceType(412): Resources don't contain package for resource number 0x7f020030
09-16 16:18:11.425: W/ResourceType(412): Resources don't contain package for resource number 0x7f050000
09-16 16:18:11.725: W/ResourceType(412): Resources don't contain package for resource number 0x7f060000
09-16 16:18:11.745: W/ResourceType(412): Resources don't contain package for resource number 0x7f060001
09-16 16:18:12.217: D/dalvikvm(458): GC freed 149 objects / 5952 bytes in 756ms
09-16 16:18:12.276: W/ResourceType(412): Resources don't contain package for resource number 0x7f0700e5
09-16 16:18:12.276: W/ResourceType(412): Resources don't contain package for resource number 0x7f020031
09-16 16:18:12.276: W/ResourceType(412): Resources don't contain package for resource number 0x7f020030
09-16 16:18:12.276: W/ResourceType(412): Resources don't contain package for resource number 0x7f050000
09-16 16:18:12.475: W/ResourceType(412): Resources don't contain package for resource number 0x7f060000
09-16 16:18:12.485: W/ResourceType(412): Resources don't contain package for resource number 0x7f060001
09-16 16:18:12.894: D/AndroidRuntime(1487): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
09-16 16:18:12.904: D/AndroidRuntime(1487): CheckJNI is ON
09-16 16:18:14.004: D/AndroidRuntime(1487): --- registering native functions ---
09-16 16:18:14.924: D/ddm-heap(1487): Got feature list request
09-16 16:18:15.854: I/ActivityManager(412): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=nl.computerhuys.simplescore/.MainActivity }
09-16 16:18:15.944: D/AndroidRuntime(1487): Shutting down VM
09-16 16:18:15.944: D/dalvikvm(1487): DestroyJavaVM waiting for non-daemon threads to exit
09-16 16:18:15.954: D/dalvikvm(1487): DestroyJavaVM shutting VM down
09-16 16:18:15.964: D/dalvikvm(1487): HeapWorker thread shutting down
09-16 16:18:15.964: D/dalvikvm(1487): HeapWorker thread has shut down
09-16 16:18:15.964: D/jdwp(1487): JDWP shutting down net...
09-16 16:18:15.964: I/dalvikvm(1487): Debugger has detached; object registry had 1 entries
09-16 16:18:15.974: D/dalvikvm(1487): VM cleaning up
09-16 16:18:16.044: E/AndroidRuntime(1487): ERROR: thread attach failed
09-16 16:18:16.134: D/dalvikvm(1487): LinearAlloc 0x0 used 639500 of 5242880 (12%)
09-16 16:18:16.644: I/ActivityManager(412): Start proc nl.computerhuys.simplescore for activity nl.computerhuys.simplescore/.MainActivity: pid=1494 uid=10028 gids={}
09-16 16:18:17.224: D/ddm-heap(1494): Got feature list request
09-16 16:18:18.604: I/ActivityManager(412): Displayed activity nl.computerhuys.simplescore/.MainActivity: 2599 ms (total 2599 ms)
09-16 16:18:23.915: D/dalvikvm(458): GC freed 2339 objects / 135960 bytes in 262ms
09-16 16:18:29.025: D/dalvikvm(568): GC freed 43 objects / 2016 bytes in 307ms

MainActivity.java after modification:

    package nl.computerhuys.simplescore;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import nl.computerhuys.simplescore.R;


public class MainActivity extends Activity implements RadioGroup.OnCheckedChangeListener,
View.OnClickListener {

    private TextView mChoice;
    private RadioGroup mRadioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        mRadioGroup = (RadioGroup) findViewById(R.id.menu);

        // test adding a radio button programmatically
        RadioButton newRadioButton = new RadioButton(this);
        newRadioButton.setText(R.string.radio_group_s1);
        newRadioButton.setId(R.id.s1);
        LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
                RadioGroup.LayoutParams.WRAP_CONTENT,
                RadioGroup.LayoutParams.WRAP_CONTENT);
        mRadioGroup.addView(newRadioButton, 0, layoutParams);

        // test listening to checked change events
        String selection = getString(R.string.radio_group_selection);
        mRadioGroup.setOnCheckedChangeListener(this);
        mChoice = (TextView) findViewById(R.id.choice);
        mChoice.setText(selection + mRadioGroup.getCheckedRadioButtonId());

        // test clearing the selection
        Button clearButton = (Button) findViewById(R.id.clear);
        clearButton.setOnClickListener(this);
    }

    public void onCheckedChanged(RadioGroup group, int checkedId) {
        String selection = getString(R.string.radio_group_selection);
        String none = getString(R.string.radio_group_none);
        mChoice.setText(selection +
                (checkedId == View.NO_ID ? none : checkedId));
    }

    public void onClick(View v) {
        mRadioGroup.clearCheck();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

Manifest after modification:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="nl.computerhuys.simplescore" android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk android:minSdkVersion="7"
        android:targetSdkVersion="16" />

    <application android:allowBackup="true" android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" android:theme="@style/AppTheme">

        <activity android:name="nl.computerhuys.simplescore.MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

     </application>

</manifest>

Activity_main.xml after modification:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/screen_background_black" >

    <RadioGroup
        android:id="@+id/menu"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/s1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/radio_group_1_s1" />

        <RadioButton
            android:id="@+id/s2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/radio_group_1_s2" />

        <RadioButton
            android:id="@+id/s3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/radio_group_1_s3" />

        <TextView
            android:id="@+id/choice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/radio_group_1_selection" />
    </RadioGroup>

    <Button
        android:id="@+id/clear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/menu"
        android:text="@string/radio_group_1_clear" />

</RelativeLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:46:03+00:00Added an answer on June 14, 2026 at 7:46 pm

    Remove the uses library from your manifest.

    Move everything that is not a RadioButton out of your ButtonGroup. Put them below your group and add xml statement to put them inside your relative layout (root level) below the RadioGroup.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/screen_background_black" >
    
          <RadioGroup
            android:id="@+id/menu"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:checkedButton="@+id/s1"
            android:orientation="horizontal" >
    
            <RadioButton
                android:id="@+id/s1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/radio_group_1_s1" />
    
            <RadioButton
                android:id="@+id/s2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                    android:text="@string/radio_group_1_s2" />
    
            <RadioButton
                android:id="@+id/s3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/radio_group_1_s3" />
            </RadioGroup>
    
            <TextView
                  android:id="@+id/choice"
                  android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@id/menu"
                  android:text="@string/radio_group_1_selection" />
    
             <Button
                  android:id="@+id/clear"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_below="@id/choice"
              android:text="@string/radio_group_1_clear" />
    </RelativeLayout>
    

    There were a couple of mistakes in your layout files :

    • the android1 prefix was useless and confusing
    • the radio groups should only contain radio buttons
    • every view must have both android:layout_width & android:layout_height attributes
    • the tools namespace and tools:context were useless
    • please configure your IDE not to use tabs but spaces. It’s quite a pain in the * to modify your indentation.

    Also you have a problem in yuor manifest : you must declare only one activity with the intent-filter to catch the launcher intent. That’s your program entry point and actually you declared two…

    Combine both activities in one for now. And don’t create new widgets programmatically, start by getting the ones you declared in your layout using findViewById. Moreover the view you created had an id that collided with one view in the manifest.

    If you decide to declare more activities later, double check that you use their fully qualified names in the manifest, you made in mistake in the RadioGroup1 activity declaration statement wih regard to that matter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Specifically, suppose I start with the string string =hello \'i am \' me And
I am currently running into a problem where an element is coming back from
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.