国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

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

2020-04-11 11:26:12
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(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>

array.xml數(shù)組:

<?xml version="1.0" encoding="utf-8"?><resources> <string-array name="hobby">  <item>游泳</item>  <item>打籃球</item>  <item>登山</item> </string-array></resources>

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ì)話框");   //添加按鈕,android.content.DialogInterface.OnClickListener.OnClickListener   builder.setItems(R.array.hobby, new OnClickListener(){    public void onClick(DialogInterface dialog, int which) {     String hoddy=getResources().getStringArray(R.array.hobby)[which];     editText.setText("您選擇了: "+hoddy);    }   });   //創(chuàng)建一個(gè)列表對(duì)話框   dialog=builder.create();   break;  }  return dialog; }}

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

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

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 平江县| 原平市| 英吉沙县| 扎囊县| 巴彦淖尔市| 鄂托克旗| 新疆| 石林| 雷州市| 房产| 张家界市| 略阳县| 开原市| 井冈山市| 文水县| 拜泉县| 中卫市| 陇川县| 建平县| 虹口区| 平利县| 通州市| 定西市| 广宁县| 中卫市| 民丰县| 安国市| 东至县| 新丰县| 昌宁县| 深水埗区| 卓资县| 海南省| 庄河市| 福安市| 巩义市| 菏泽市| 台东市| 南阳市| 柳河县| 大新县|