为什么点击按钮后信息没出来呢?求解答
public class MainActivity extends Activity {
String [] liString = {"篮球","篮球","羽毛球"};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dialogshow1();
dialogshow2();
}
private void dialogshow1(){
findViewById(R.id.btn1).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
showDialog1();
}
});
}
private void dialogshow2(){
findViewById(R.id.btn2).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
showDialog2();
}
});
}
private void showDialog1(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("确认对话框");
builder.setIcon(R.drawable.ic_launcher);
builder.setMessage("确定要结束此程序吗?");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(MainActivity.this, "退出程序", Toast.LENGTH_LONG).show();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(MainActivity.this, "继续此程序", Toast.LENGTH_LONG).show();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
private void showDialog2(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("单项选择对话框");
builder.setIcon(R.drawable.ic_launcher);
builder.setMessage("请选择你的信息");
builder.setSingleChoiceItems(liString, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String string = liString[which];
Toast.makeText(MainActivity.this, "爱好是" + string, Toast.LENGTH_LONG).show();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}