国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 丽江市| 安丘市| 洪洞县| 平阴县| 平阳县| 关岭| 社会| 盐城市| 津市市| 眉山市| 抚顺县| 简阳市| 平乡县| 柳林县| 合作市| 日土县| 藁城市| 嘉峪关市| 陇南市| 南部县| 澄迈县| 钟祥市| 罗城| 南康市| 精河县| 无棣县| 砀山县| 富蕴县| 尼木县| 张掖市| 松江区| 九江县| 南汇区| 敖汉旗| 永德县| 伊春市| 原阳县| 呼伦贝尔市| 盐池县| 滦平县| 辽阳县|