a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 系統 > Android > 正文

Android編程實現Dialog窗體監聽的方法

2019-12-12 03:28:47
字體:
來源:轉載
供稿:網友

本文實例講述了Android編程實現Dialog窗體監聽的方法。分享給大家供大家參考,具體如下:

今天做了一個Dialong窗體監聽包括窗體內的xml監聽。

效果圖:

test.class代碼

package com.test;import Android.app.Activity;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.os.Bundle;import android.text.Layout;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageButton;import android.widget.ImageView;import android.widget.TextView;public class test extends Activity implements OnClickListener {  private ImageButton button=null;  @Override  public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    button=(ImageButton)findViewById(R.id.button);    //監聽    button.setOnClickListener(this);  }  @Override  public void onClick(View v) {    Windows();  }  private void Windows() {  //接受一些參數如:圖片,標題,正文  AlertDialog.Builder builder;  AlertDialog alertDialog;  //加載和訪問資源  Context mContext =test.this;  //通過LayoutInlater得到上面xml布局的View view  LayoutInflater inflater =  (LayoutInflater)mContext.getSystemService(LAYOUT_INFLATER_SERVICE);  View layout =inflater.inflate(R.layout.custom_dialog,null);  //綁定test和image  TextView text=(TextView)layout.findViewById(R.id.text);  text.setText("hello");  Button b =(Button)layout.findViewById(R.id.b);  b.setText("butto");  b.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View v) {      System.out.println("123");    }  });  ImageView image=(ImageView)layout.findViewById(R.id.image);  //取出系統自帶的圖片  image.setImageResource(R.drawable.icon);  //加載  builder = new AlertDialog.Builder(mContext);  builder.setView(layout);  //創建目標,這里創建相應的AlertDialog//  alertDialog = builder.create();  //彈出窗口  builder.setPositiveButton("確定", new DialogInterface.OnClickListener() {    @Override    public void onClick(DialogInterface dialog,     int which) {    }    }).setNegativeButton("取消",    new DialogInterface.OnClickListener() {    @Override    public void onClick(DialogInterface dialog,     int which) {     dialog.cancel();    }    }).create();  builder.show();  }}

custom_dialog.xml文件代碼

<?xml version="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="horizontal"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:padding="10dp"    > <ImageView android:id="@+id/image"    android:layout_width="wrap_content"    android:layout_height="fill_parent"    android:layout_marginRight="10dp"    /> <TextView android:id="@+id/text"    android:layout_width="wrap_content"    android:layout_height="fill_parent"    android:textColor="#FFF"    />    <Button android:id="@+id/b"    android:layout_width="wrap_content"    android:layout_height="fill_parent"    /></LinearLayout>

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"  ><TextView  android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:text="@string/hello"  />  <ImageButton  android:id="@+id/button"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:background="#000000"  android:src="@drawable/icon"  /></LinearLayout>

結尾:由于要用到兩個xml所以這里有兩個xml的代碼,一個是點擊按鈕的xml代碼,一個窗體里面的xml布局帶

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android開發入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 精品久久久久久 | 亚洲成人免费 | 99精品欧美一区二区三区综合在线 | 国产一级淫免费播放m | 超黄视频在线观看 | 久草视频在线播放 | 日韩久草| 久久激情网 | 日韩欧美国产网站 | 久久久免费视频播放 | 九九九九九九精品 | 欧美三级在线 | 成人黄色一级网站 | 中文字幕在线视频第一页 | 亚洲三级视频 | 欧美大片在线免费观看 | a级淫片 | 国产中文字幕亚洲 | 一区不卡| 一区二区免费 | 成人一区二区三区在线观看 | 一区二区三区亚洲视频 | 偷拍自拍网站 | 国产偷国产偷精品高清尤物 | 色综合一区二区三区 | 日韩一及片| 亚洲欧美一区二区三区在线 | 欧美一级视频 | 中文字幕亚洲一区 | 国产美女在线精品免费 | 国产精品片一区二区三区 | 久久久久一区二区三区 | 精品久久影院 | 色噜噜狠狠色综合中国 | 成人在线免费观看 | 精品国产一区二区三区av小说 | 成人性视频免费网站 | 久久综合热 | 国产精品国产三级国产有无不卡 | 毛片久久 | 亚洲第一av |