如何根据选中的单选按钮传递意图值,只有在单击按钮后才应该启动意图,并且应该根据 swith case 语句传递值这里是我的代码,请帮帮我..
package com.example.simplemath;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
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.util.Log;
public class Settings extends Activity {
OnCheckedChangeListener listner = null;
OnCheckedChangeListener listner2 = null;
int level = 0;
int TotalQues = 0;
int click = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
Bundle b = getIntent().getExtras();
click = b.getInt("click");
Typeface custom_font = Typeface.createFromAsset(getAssets(),
"fonts/SofadiOne-Regular.ttf");
Typeface custom_font1 = Typeface.createFromAsset(getAssets(),
"fonts/belligerent.ttf");
TextView heading1 = (TextView) findViewById(R.id.textView1);
heading1.setTypeface(custom_font);
TextView heading2 = (TextView) findViewById(R.id.textView2);
heading2.setTypeface(custom_font);
RadioGroup difficulty = (RadioGroup) findViewById(R.id.radioGroup1);
difficulty.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (group.getCheckedRadioButtonId()) {
case R.id.radioButton1:
Log.d("info", "one");
Intent intent1 = new Intent(Settings.this, Third.class);
level = 1;
intent1.putExtra("level", level);
intent1.putExtra("click", click);
// startActivity(intent1);
break;
case R.id.radioButton2:
Log.d("info", "two");
Intent intent2 = new Intent(Settings.this, Third.class);
level = 2;
intent2.putExtra("level", level);
intent2.putExtra("click", click);
// startActivity(intent2);
break;
case R.id.radioButton3:
Log.d("info", "three");
Intent intent3 = new Intent(Settings.this, Third.class);
level = 3;
intent3.putExtra("level", level);
intent3.putExtra("click", click);
// startActivity(intent2);
break;
}
}
});
RadioGroup NoOfQuestions = (RadioGroup) findViewById(R.id.radioGroup2);
NoOfQuestions.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (group.getCheckedRadioButtonId()) {
case R.id.radioButton4:
Log.d("info", "four");
Intent intent4 = new Intent(Settings.this, Third.class);
Bundle NoTwenty = new Bundle();
TotalQues = 1;
NoTwenty.putInt("NoQuestions", TotalQues);
intent4.putExtras(NoTwenty);
// startActivity(intent4);
break;
case R.id.radioButton5:
Log.d("info", "five");
Intent intent5 = new Intent(Settings.this, Third.class);
Bundle NoThirty = new Bundle();
TotalQues = 1;
NoThirty.putInt("NoQuestions", TotalQues);
intent5.putExtras(NoThirty);
// startActivity(intent5);
break;
case R.id.radioButton6:
Log.d("info", "six");
Intent intent6 = new Intent(Settings.this, Third.class);
Bundle NoFourty = new Bundle();
TotalQues = 1;
NoFourty.putInt("NoQuestions", TotalQues);
intent6.putExtras(NoFourty);
// startActivity(intent6);
break;
}
}
});
RadioButton easy = (RadioButton) findViewById(R.id.radioButton1);
easy.setTypeface(custom_font1);
RadioButton medium = (RadioButton) findViewById(R.id.radioButton2);
medium.setTypeface(custom_font1);
RadioButton hard = (RadioButton) findViewById(R.id.radioButton3);
hard.setTypeface(custom_font1);
RadioButton twenty = (RadioButton) findViewById(R.id.radioButton4);
twenty.setTypeface(custom_font1);
RadioButton thirty = (RadioButton) findViewById(R.id.radioButton5);
thirty.setTypeface(custom_font1);
RadioButton fourty = (RadioButton) findViewById(R.id.radioButton6);
fourty.setTypeface(custom_font1);
Button submit = (Button) findViewById(R.id.button1);
submit.setTypeface(custom_font);
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(Settings.this, Third.class));
}
});
}
}