为什么我的是一片空白呢?
package com.sorgs.administrator.dialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
String[] single_list = {"男", "女", "女博士", "程序员"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
//初始化点击事件
public void initEvent() {
findViewById(R.id.dialog_btn1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showDialog1();
}
});
findViewById(R.id.dialog_btn2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showDialog2();
}
});
}
//显示确认对话框
private void showDialog1() {
Builder builder = new Builder(this);
builder.setTitle("确认对话框"); //设置标题
builder.setIcon(R.mipmap.ic_launcher); //设置图标
builder.setMessage("确认对话框提示内容"); //设置内容
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this, "点击了确定按钮!", Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this, "点击了取消按钮!", Toast.LENGTH_SHORT).show();
}
});
AlertDialog dialog = builder.create(); //获取dialog
dialog.show(); //显示对话框
}
private void showDialog2() {
Builder builder = new Builder(this);
builder.setTitle("选择性别"); //设置标题
builder.setIcon(R.mipmap.ic_launcher); //设置图标
builder.setSingleChoiceItems(single_list, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String str = single_list[i];
Toast.makeText(MainActivity.this, "这个人是"+str, Toast.LENGTH_SHORT).show();
}
});
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this, "点击了确定按钮!", Toast.LENGTH_SHORT).show();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<Button
android:id="@+id/dialog_btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="确认对话框"/>
<Button
android:id="@+id/dialog_btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="单选按钮对话框"/>
</LinearLayout>