Brilliant stuff Umesh, thanks! You've taught me a lot there! I've one more question if you don't mind.
I would now like to choose one radio button from each radiogroup (for Example, Chinese, Level 1, Guess the City) and then have the message at the top read "You chose Chinese, Level 1, Guess the City". How can I write this in the Java script. so far I have:
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private RadioGroup radioGroup1;
private RadioGroup radioGroup2;
private RadioGroup radioGroup3;
private RadioButton chinese, indian, russian;
private Button button;
private TextView textView;
public String string_first_radiogroup;
public String string_second_radiogroup;
public String string_third_radiogroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioGroup1 = (RadioGroup) findViewById(R.id.radio1);// your radio group1
radioGroup2 = (RadioGroup) findViewById(R.id.radio2);// your radio group2
radioGroup3 = (RadioGroup) findViewById(R.id.radio3);// your radio group3
radioGroup1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// find which radio button is selected
if(checkedId == R.id.chinese) {
string_first_radiogroup="Chinese"; // String updated on radio check
} else if(checkedId == R.id.indian) {
string_first_radiogroup="Indian"; // String updated on radio check
} else {
string_first_radiogroup="Russian"; // String updated on radio check
}
}
});
chinese = (RadioButton) findViewById(R.id.chinese);
indian = (RadioButton) findViewById(R.id.indian);
russian = (RadioButton) findViewById(R.id.russian);
textView = (TextView) findViewById(R.id.text);
radioGroup1.check(R.id.chinese);// setting Chinese selected by default
string_first_radiogroup="Chinese"; //setting "Chinese" by default in string also
radioGroup2.check(R.id.difficulty1);
string_second_radiogroup="Level 1 (Starter)";
button = (Button)findViewById(R.id.choose);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
textView.setText("You chose " + string_first_radiogroup + " option");
textView.setText("You chose " + string_second_radiogroup + " option");
}
});
}
}