DialogTest.java

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
     >
	<TextView
	    android:id="@+id/username"
	    android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginLeft="20dip"
		android:layout_marginRight="20dip"
		android:text="@string/account"
		android:gravity="left"
		android:textAppearance="?android:attr/textAppearanceMedium"
		></TextView>
	<EditText
	    android:id="@+id/usernameinput"
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"
	    android:layout_marginLeft="20dip"
	    android:layout_marginRight="20dip"
	    ></EditText>
	
	<TextView
	    android:id="@+id/username"
	    android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginLeft="20dip"
		android:layout_marginRight="20dip"
		android:text="@string/password"
		android:gravity="left"
		android:textAppearance="?android:attr/textAppearanceMedium"
		></TextView>
	<EditText
	    android:id="@+id/usernameinput"
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"
	    android:layout_marginLeft="20dip"
	    android:layout_marginRight="20dip"
	    ></EditText>
</LinearLayout>


 

 

/*
 * 这个程序是一DialogTest。java
 * 顾名思义,作用就是测试Dialog的用法  
 * AlertDialog  是点击之后才显示的   Dialog是自动直接显示的
 * 在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById()。
 * 不同点是LayoutInflater是用来找res/layout/下的xml布局文件,
 * 并且实例化;而findViewById()是找xml布局文件下的具体widget控件(如 Button、TextView等)。
 * public static LayoutInflater from (Context context) 
	 Obtains the LayoutInflater from the given context. 
   public AlertDialog.Builder (Context context) 
     Constructor using a context for this builder and the AlertDialog it creates.
   public static ProgressDialog show (Context context, CharSequence title, CharSequence message) 
    并且要注意  try catch  是你不用写的 你写了 就累了自己了
    public View inflate (int resource, ViewGroup root) 
Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.

Parameters
resource  ID for an XML layout resource to load (e.g., R.layout.main_page) 
root  Optional view to be the parent of the generated hierarchy. 

*/
package com.example.dialogtest;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

public class DialogTest extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		//父类的其他方法继续使用
		super.onCreate(savedInstanceState);
		//设置主界面的layout 
		setContentView(R.layout.main);
		Dialog dialog = new AlertDialog.Builder(DialogTest.this)

		.setTitle("wuxinliulei:登陆提示")

		.setMessage("这里需要登陆!")

		.setPositiveButton("确定", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				LayoutInflater factory = LayoutInflater.from(DialogTest.this);
				//获得layout对象
				final View DialogView = factory.inflate(R.layout.dialog, null);

				AlertDialog dlg = new AlertDialog.Builder(DialogTest.this)

						.setTitle("wuxinliulei:登陆")
						//第一个Dialog   dialog  由于没有widget组件 没有下面这句话
						.setView(DialogView)

						.setPositiveButton("登陆",
								new DialogInterface.OnClickListener() {

									@Override
									public void onClick(DialogInterface dialog,
											int which) {
										// 添加登陆处理界面
										final ProgressDialog myDialog = ProgressDialog
												.show(DialogTest.this, "请等待",
														"正在登陆");
										new Thread() {
											public void run() {
												try {
													sleep(1000);
												} catch (InterruptedException e) {

													e.printStackTrace();
												} finally {
													myDialog.dismiss();
												}
											}
										}.start();
									}
								})
					
						.setNegativeButton("退出",
								new DialogInterface.OnClickListener() {

									@Override
									public void onClick(DialogInterface dialog,
											int which) {
										DialogTest.this.finish();// 如果什么都不加的话,点击退出之后就会回到主界面
																	// 但是如果加上这句话就会退出程序

									}
								})
								
						.create();
					dlg.show();
			}
		})
		
		.setNegativeButton("取消", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				DialogTest.this.finish();// 如果什么都不加的话,点击退出之后就会回到主界面
											// 但是如果加上这句话就会退出程序

			}
		})
		
		.create();

		dialog.show();
	}

}


 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值