• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Please help a beginner

I am making a very basic android app, but I need some help on some parts. Basically, the app displays two radio groups, with three radio buttons per group. After selecting a radio button from each group, the user clicks another button (let's just call it "Done"), which records which radio buttons are selected and, based on that information, will launch another activity (so there are nine different activities that could be launched). Here are my questions:

1) How do I make it so that when the user clicks Done, the program will check which radio buttons are selected and then know which activity to launch? I was thinking of using a switch statement, but I am unsure how to write the code for that.

2) Is there a way to set up default selections for both radio groups?

Any help is appreciated.
 
Here is the code in my XML file:
Code:
<?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"
    >
	<TextView  
    	android:layout_width="fill_parent" 
    	android:layout_height="wrap_content" 
    	android:text="Select the protagonist:"
    	/>
    
	<RadioGroup android:id="@+id/protagonist"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:orientation="vertical"
		>
		<RadioButton android:id="@+id/Jacobs"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:text="Jacobs" 
			/>
		<RadioButton android:id="@+id/Bolverk"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:text="Bolverk" 
			/>
		<RadioButton android:id="@+id/HappyGoLucky"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:text="Happy Go Lucky" 
			/>
	</RadioGroup>
	
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:text="Select the plot:"
		/>
		
	<RadioGroup android:id="@+id/plot"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:orientation="vertical"
		>
		<RadioButton android:id="@+id/park"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:text="Hangs out in the park" 
			/>
		<RadioButton android:id="@+id/town"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:text="Goes into town" 
			/>
		<RadioButton android:id="@+id/holiday"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:text="Saves a certain December holiday" 
			/>
	</RadioGroup>
	
	<Button
		android:id="@+id/Launch"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="Launch"
		android:layout_alignParentLeft="true"
		android:layout_alignParentRight="true"
		/>
		
</LinearLayout>
 
1) You would make an action listener for the button in java that would check if the radio buttons is checked and then write also in Java code what activity to launch.

2) Yes there is.

I realy recomend if you want to make android apps that you should learn Java its a programing language that is realy good to know if you want to make apps since if you made some buttons for example as you did in xml you can write in Java what the button does and many many many other things.. That was just an example..

I will here provide you with some links to learn more about Java:
Trail: Getting Started (The Java
 
You can then pass that info to the next activity in an intent, or store it in SharedPreferences, and have the next activity read it from there.
 
Back
Top Bottom