欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android普通對(duì)話框用法實(shí)例分析

 更新時(shí)間:2015年09月16日 12:06:53   作者:Ruthless  
這篇文章主要介紹了Android普通對(duì)話框用法,以實(shí)例形式較為詳細(xì)的分析了Android對(duì)話框的創(chuàng)建技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Android普通對(duì)話框用法。分享給大家供大家參考。具體如下:

main.xml布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <EditText android:text="" 
  android:id="@+id/editText"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" 
  android:editable="false"
  android:cursorVisible="false" />
 <Button android:text="顯示普通對(duì)話框" 
  android:id="@+id/button"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" />
</LinearLayout>

AlertDialog類:

package com.ljq.dialog;
import android.app.Activity;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class AlertDialog extends Activity {
 private EditText editText;
 private final static int DIALOG=1;
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  editText=(EditText)findViewById(R.id.editText);
  Button button = (Button) findViewById(R.id.button);
  button.setOnClickListener(new View.OnClickListener() {
   public void onClick(View v) {
    // 顯示對(duì)話框
    showDialog(DIALOG);
   }
  });
 }
 /**
  * 創(chuàng)建普通對(duì)話框
  */
 @Override
 protected Dialog onCreateDialog(int id) {
  Dialog dialog=null;
  switch (id) {
  case DIALOG:
   Builder builder=new android.app.AlertDialog.Builder(this);
   //設(shè)置對(duì)話框的圖標(biāo)
   builder.setIcon(R.drawable.header);
   //設(shè)置對(duì)話框的標(biāo)題
   builder.setTitle("普通對(duì)話框");
   //設(shè)置對(duì)話框的顯示內(nèi)容
   builder.setMessage("這是普通對(duì)話框中的內(nèi)容!!");
   //添加按鈕,android.content.DialogInterface.OnClickListener.OnClickListener
   builder.setPositiveButton(" 確 定 ", new OnClickListener(){
    public void onClick(DialogInterface dialog, int which) {
     editText.setText("這是普通對(duì)話框中的內(nèi)容!!");
    }
   });
   //創(chuàng)建一個(gè)普通對(duì)話框
   dialog=builder.create();
   break;
  }
  return dialog;
 }
}

運(yùn)行結(jié)果:

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論