Caiquan.java //Next.java 在这里就不一一列举了,不然就是一堆代码
import android.*; //都是自动导的包,在这里我就省略了。
public class Caiquan extends Activity {
private RadioGroup radioGroup1,radioGroup;
private RadioButton shitouButton1,buButton1,jiandaoButton1;
private RadioButton jiandaoButton,buButton,shitouButton;
private Button button1,button2;
private TextView textview1,textview;
private ImageView imageview;
private ImageView imageview1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_caiquan);
textview1=(TextView)findViewById(R.id.textView1);
textview=(TextView)findViewById(R.id.game);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(new ButtonListener());
button2.setOnClickListener(new ButtonListener());
radioGroup=(RadioGroup)findViewById(R.id.radioGroupId);
radioGroup1=(RadioGroup)findViewById(R.id.radioGroupId1);
shitouButton1=(RadioButton)findViewById(R.id.radioButton1);
buButton1=(RadioButton)findViewById(R.id.radioButton3);
jiandaoButton1=(RadioButton)findViewById(R.id.radioButton5);
jiandaoButton=(RadioButton)findViewById(R.id.radioButton2);
shitouButton=(RadioButton)findViewById(R.id.radioButton4);
buButton=(RadioButton)findViewById(R.id.radioButton6);
RadioButtonListener Radiolistener = new RadioButtonListener();
shitouButton1.setOnCheckedChangeListener(Radiolistener);
buButton1.setOnCheckedChangeListener(Radiolistener);
jiandaoButton1.setOnCheckedChangeListener(Radiolistener);
jiandaoButton.setOnCheckedChangeListener(Radiolistener);
shitouButton.setOnCheckedChangeListener(Radiolistener);
buButton.setOnCheckedChangeListener(Radiolistener);
imageview1 = (ImageView) findViewById(R.id.imageView1);
imageview = (ImageView) findViewById(R.id.imageView2);
} //在这里也可以为findViewById 方法和绑定监听器 设置两个方法
class ButtonListener implements OnClickListener{
private String win;
@Override
public void onClick(View v) {
RadioButton radioButtonleft = (RadioButton) findViewById(radioGroup1
.getCheckedRadioButtonId());
String radioTextleft = radioButtonleft.getText().toString();
RadioButton radioButtonright = (RadioButton) findViewById(radioGroup
.getCheckedRadioButtonId());
String radioTextright = radioButtonright.getText().toString();
Intent intent= new Intent();
intent.setClass(Caiquan.this, Next.class);
intent.putExtra("checked", radioTextleft);
intent.putExtra("checked", radioTextright);
intent.putExtra("com.Jackson.game_intent.jieguo", win);
startActivity(intent); }
}// 用radioText记录被选中的单选按钮的值,传达到下一个 Activity
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.caiquany, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return false;
}}