android对话框应用
啥都别说了,看效果吧!
1代码
new AlertDialog.Builder(Lesson_01_Pic.this).setTitle("提示标题").setMessage("这是提示内容").show();
2代码
new AlertDialog.Builder(Lesson_01_Pic.this)
.setTitle("这是标题")
.setMessage("这是提示内容")
.setPositiveButton("确定",
new DialogInte易做图ce.OnClickListener(){
public void onClick(DialogInte易做图ce dialoginte易做图ce, int i){
//按钮事件
Toast.makeText(Lesson_01_Pic.this, "确定",Toast.LENGTH_LONG).show();
}
}).show();
3代码
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInte易做图ce;
import android.content.DialogInte易做图ce.OnClickListener;
import android.content.DialogInte易做图ce.OnMultiChoiceClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class Lesson_02_Dia extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.b01);
button.setText("对话框");
button.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
//选项数组
String[] choices={"Facebook","Twitter"};
//Check判断数组,与选项对应
boolean[] chsBool = {true,false};
//包含多个选项及复选框的对话框
AlertDialog dialog = new AlertDialog.Builder(Lesson_02_Dia.this)
.setIcon(android.R.drawable.btn_star_big_on)
.setTitle("调查")
.setMultiChoiceItems(choices, chsBool, multiClick)
.setPositiveButton("Yes", onclick)
.setNegativeButton("No", onclick).create();
dialog.show();
}
});
}
/**
* 对话框复选框事件易做图
*/
OnMultiChoiceClickListener multiClick = new OnMultiChoiceClickListener(){
@Override
public void onClick(DialogInte易做图ce dialog, int which, boolean isChecked) {
Toast.makeText(Lesson_02_Dia.this, "第"+(which+1)+"项,选中结果:"+isChecked,Toast.LENGTH_SHORT).show();
}
};
/**
* 对话框按钮点击事件易做图
*/
OnClickListener onclick = new OnClickListener() {
@Override
public void onClick(DialogInte易做图ce dialog, int which) {
switch (which) {
case Dialog.BUTTON_NEGATIVE:
Toast.makeText(Lesson_02_Dia.this, "No..",
&
补充:移动开发 , Android ,