模拟器上程序停止运行
package com.example.radiogroup;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements OnCheckedChangeListener{
private RadioButton RB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RB=(RadioButton) findViewById(R.id.radioGroup1);
RB.setOnCheckedChangeListener((android.widget.CompoundButton.OnCheckedChangeListener) this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
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 super.onOptionsItemSelected(item);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch(checkedId){
case R.id.radio0:
Toast.makeText(MainActivity.this, "哦,男的啊", 1).show();
break;
case R.id.radio1:
Toast.makeText(MainActivity.this, "yooooooooo!", 1).show();
break;
case R.id.radio2:
Toast.makeText(MainActivity.this, "美女!叫啥名啊?有微信吗?", 1).show();
}
}
}编译的时候没问题,在模拟器上停止运行。不知道什么原因!!
