Android列表對(duì)話框用法實(shí)例分析
本文實(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類(lèi):
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ì)有所幫助。
- Android之復(fù)選框?qū)υ捒蛴梅▽?shí)例分析
- Android普通對(duì)話框用法實(shí)例分析
- Android單選按鈕對(duì)話框用法實(shí)例分析
- Android之日期及時(shí)間選擇對(duì)話框用法實(shí)例分析
- android幾種不同對(duì)話框的實(shí)現(xiàn)方式
- Android開(kāi)發(fā)必知 九種對(duì)話框的實(shí)現(xiàn)方法
- Android實(shí)現(xiàn)點(diǎn)擊AlertDialog上按鈕時(shí)不關(guān)閉對(duì)話框的方法
- Android中創(chuàng)建一個(gè)透明的進(jìn)度對(duì)話框?qū)嵗?/a>
- Android復(fù)選框?qū)υ捒蛴梅▽?shí)例簡(jiǎn)析
相關(guān)文章
Android仿IOS ViewPager滑動(dòng)進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了Android仿IOS ViewPager滑動(dòng)進(jìn)度條的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01
Android藍(lán)牙通信聊天實(shí)現(xiàn)發(fā)送和接受功能
這篇文章主要為大家詳細(xì)介紹了Android藍(lán)牙通信聊天實(shí)現(xiàn)發(fā)送和接受功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07
Flutter實(shí)現(xiàn)切換應(yīng)用時(shí)隱藏應(yīng)用預(yù)覽
如果您要顯示敏感數(shù)據(jù),例如錢(qián)包金額,或者只是當(dāng)?shù)卿洷韱物@示插入的密碼清晰時(shí),當(dāng)您不在應(yīng)用程序中時(shí),您必須隱藏敏感數(shù)據(jù)。本文將利用Flutter實(shí)現(xiàn)切換應(yīng)用時(shí)隱藏應(yīng)用預(yù)覽,需要的可以參考一下2022-06-06
Android中協(xié)調(diào)滾動(dòng)布局的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android中協(xié)調(diào)滾動(dòng)常用的布局實(shí)現(xiàn),類(lèi)似這樣的協(xié)調(diào)滾動(dòng)布局,當(dāng)?shù)撞苛斜砘瑒?dòng)的時(shí)候,頂部的布局做響應(yīng)的動(dòng)作,我們都可以通過(guò)?AppBarLayout?和?MotionLayout?來(lái)實(shí)現(xiàn),本文通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友參考下吧2022-06-06
Android自定義View實(shí)現(xiàn)風(fēng)車(chē)效果
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)風(fēng)車(chē)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08

