关闭

android 随手记 弹出对话框

标签: android对话框
983人阅读 评论(0) 收藏 举报
分类:
package Rw.Dialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class Dialog01Activity extends Activity {
 
    private Button button1,button2,button3,button4,button6,button7;
    ProgressDialog progressDialog=null;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        button1=(Button)findViewById(R.id.button1);
        button2=(Button)findViewById(R.id.button2);
        button3=(Button)findViewById(R.id.button3);
        button4=(Button)findViewById(R.id.button4);
        button6=(Button)findViewById(R.id.button6);
        button7=(Button)findViewById(R.id.button7);
  
        button1.setOnClickListener(new ButtonListener());
        button2.setOnClickListener(new ButtonListener());
        button3.setOnClickListener(new ButtonListener());
        button4.setOnClickListener(new ButtonListener());
        button6.setOnClickListener(new ButtonListener());
        button7.setOnClickListener(new ButtonListener());
    }
   
    class ButtonListener implements OnClickListener{

		@Override
		public void onClick(View v) {
			 final String[] itemStrings={"AA","BB","CC","DD"};
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.button1:
				 AlertDialog.Builder dialog=new AlertDialog.Builder(Dialog01Activity.this);
				   dialog.setTitle("Dialog").setIcon(android.R.drawable.ic_dialog_info).setMessage("弹出框").setPositiveButton("确定", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						//转跳到另外一个Activity
						// TODO Auto-generated method stub
						Intent intent=new Intent();
						intent.setClass(getApplicationContext(), list.class);
						startActivity(intent);
					}
				}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
					
					
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						dialog.cancel();//取消弹出框
					}
				}).create().show();
				break;
			case R.id.button2:
				
				AlertDialog.Builder builder=new AlertDialog.Builder(Dialog01Activity.this);
				builder.setTitle("LIST").setIcon(android.R.drawable.ic_lock_lock).setItems(itemStrings, new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
					Toast.makeText(getApplicationContext(), "你点击的是"+itemStrings[which], Toast.LENGTH_LONG).show();	
					}
				}).create().show();
				break;
            case R.id.button3:
                
				AlertDialog.Builder builder1=new AlertDialog.Builder(Dialog01Activity.this);
				builder1.setTitle("LIST").setIcon(android.R.drawable.ic_lock_lock).setSingleChoiceItems(itemStrings,-1, new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
					Toast.makeText(getApplicationContext(), "你点击的是"+itemStrings[which], Toast.LENGTH_LONG).show();	
					
					}
				}).create().show();
				builder1.setCancelable(true);
				break;
				case R.id.button4:
	      			progressDialog=ProgressDialog.show(Dialog01Activity.this, "下载", "下载中.....",true);
					progressDialog.setCancelable(true);//当点击按钮返回的时候Dialog消失
					//progressDialog.dismiss();
					break;
					
				case R.id.button6:
					LayoutInflater inflater=(LayoutInflater)getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
					View view=inflater.inflate(R.layout.style, null);
					AlertDialog.Builder builder2=new AlertDialog.Builder(Dialog01Activity.this);
					builder2.setView(view);
					builder2.setTitle("QQ2011").setPositiveButton("确定", new DialogInterface.OnClickListener() {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							// TODO Auto-generated method stub
							dialog.cancel();
						}
					}).create().show();
				   
					break;
				case R.id.button7:
					Dialog01Activity.this.finish();
						break;
			default:
				break;
			}
		}
    	
    }
}


主页面

 Android 弹出对话框Dialog Android 弹出对话框Dialog

Android 弹出对话框Dialog  Android 弹出对话框Dialog Android 弹出对话框Dialog

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:110757次
    • 积分:1826
    • 等级:
    • 排名:千里之外
    • 原创:70篇
    • 转载:25篇
    • 译文:0篇
    • 评论:15条
    最新评论