
在values.xml新建interest.xml文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
</LinearLayout>
.java文件
package com.example.dialogdemo;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
private Button button=null;
private View interests=null;
private TextView mysel=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.button=(Button) super.findViewById(R.id.interest);
this.mysel=(TextView) super.findViewById(R.id.mysel);
//为我们的图片添加事件
this.button.setOnClickListener(new OnClickListenerImp());
}
public class OnClickListenerImp implements OnClickListener{
public void onClick(View arg0) {
Dialog dialog=new AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.ic_launcher)
.setTitle("选择您的兴趣爱好")
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
//设置多选提示框
.setItems(R.array.selinterest, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
MainActivity.this.mysel.setText("您选择的爱好是"+MainActivity.this.getResources().getStringArray(R.array.selinterest)[which]);
}
})
.create();
dialog.show();
}
}
}