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

Apps How can my Radiogroup hold the data?

So i am programming a Quiz app for a school program, The app has 10 pages with a question on each.

On the question pages i have a next button, and back button, a textView and a radioGroup with 4 radioButtons. I want my code to be able to hold the data, so that if say 1 question is answered with the 3rd. radiobutton the app holds this data while i continue to the next page.

This is the Jave code [


public class Question1 extends Activity {


[HIGH]public void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_question1);
((RadioGroup) findViewById(R.id.radio_group))
.setOnCheckedChangeListener((OnCheckedChangeListener) this);
}

public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
switch (checkedId) {
case R.id.first_radio_button:
break;
case R.id.second_radio_button:
break;
case R.id.third_radio_button:
break;
case R.id.fourth_radio_button:
break;
}
}

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

}[/HIGH]


and this is the XML
[HIGH] <RadioGroup
android:id="@+id/radio_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="40dp"
android:orientation="vertical" >

<RadioButton
android:id="@+id/first_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:paddingLeft="40dip"
android:text="@string/Ans1" />

<RadioButton
android:id="@+id/second_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:paddingLeft="40dip"
android:text="@string/Ans2" />

<RadioButton
android:id="@+id/third_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:paddingLeft="40dip"
android:text="@string/Ans3" />

<RadioButton
android:id="@+id/fourth_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:paddingLeft="40dip"
android:text="@string/Ans4" >
</RadioButton>
</RadioGroup>[/HIGH]


Any idea how i could make it happend? or general pointers on the app, this is my very first Android and Java protject :)

Regards Jonas
 
This really all depends on how you have your application setup. If you are using separate activities for each page, then you will need to save it I suggest SharedPreferences. If you use a ViewPager, then you just need to setup the maximum number of pages to keep in memory by using this code:

[HIGH]viewPager.setOffscreenPageLimit(5);[/HIGH]
 
Each page is a new Activity.. this might have been a bad decision?

We have a Database (MySQL) that we are going to somehow send the data to which is the point of the app.

So the idea is that when the day is over we will check who has the right answers and pick a random guy or girl who will then win a Asus Nexus tablet or something like that.

So each page is a new Activity. The data should be stored until finaly send to the MySQL database.

If you have any idea how to simplyfi this or how we could pull it off please let me know. We might have bitten off more than we can chew for our first app hehe :)
 
Back
Top Bottom