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

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

 更新時(shí)間:2015年09月16日 11:48:30   作者:Ruthless  
這篇文章主要介紹了Android列表對話框用法,實(shí)例分析了Android實(shí)現(xiàn)列表對話框的布局、設(shè)置及功能等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

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

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="顯示列表對話框" 
  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) {
    // 顯示對話框
    showDialog(DIALOG);
   }
  });
 }
 /**
  * 創(chuàng)建列表對話框
  */
 @Override
 protected Dialog onCreateDialog(int id) {
  Dialog dialog=null;
  switch (id) {
  case DIALOG:
   Builder builder=new android.app.AlertDialog.Builder(this);
   //設(shè)置對話框的圖標(biāo)
   builder.setIcon(R.drawable.header);
   //設(shè)置對話框的標(biāo)題
   builder.setTitle("列表對話框");
   //添加按鈕,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è)列表對話框
   dialog=builder.create();
   break;
  }
  return dialog;
 }
}

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

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

相關(guān)文章

  • Android隱藏標(biāo)題狀態(tài)欄的方法

    Android隱藏標(biāo)題狀態(tài)欄的方法

    這篇文章主要介紹了Android隱藏標(biāo)題狀態(tài)欄的方法的相關(guān)資料,需要的朋友可以參考下
    2016-01-01
  • Android仿IOS ViewPager滑動(dòng)進(jì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ā)送和接受功能

    Android藍(lán)牙通信聊天實(shí)現(xiàn)發(fā)送和接受功能

    這篇文章主要為大家詳細(xì)介紹了Android藍(lán)牙通信聊天實(shí)現(xiàn)發(fā)送和接受功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-07-07
  • 詳解Android Lint的原理及其使用

    詳解Android Lint的原理及其使用

    這篇文章主要介紹了詳解Android Lint的原理及其使用,想了解Lint的同學(xué),一定要著重看一下
    2021-04-04
  • Flutter實(shí)現(xiàn)切換應(yīng)用時(shí)隱藏應(yīng)用預(yù)覽

    Flutter實(shí)現(xiàn)切換應(yīng)用時(shí)隱藏應(yīng)用預(yù)覽

    如果您要顯示敏感數(shù)據(jù),例如錢包金額,或者只是當(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)代碼

    這篇文章主要介紹了Android中協(xié)調(diào)滾動(dòng)常用的布局實(shí)現(xiàn),類似這樣的協(xié)調(diào)滾動(dòng)布局,當(dāng)?shù)撞苛斜砘瑒?dòng)的時(shí)候,頂部的布局做響應(yīng)的動(dòng)作,我們都可以通過?AppBarLayout?和?MotionLayout?來實(shí)現(xiàn),本文通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友參考下吧
    2022-06-06
  • Android5.0新控件實(shí)例詳解

    Android5.0新控件實(shí)例詳解

    谷歌在推出Android5.0的同時(shí)推出了一些新控件,Android5.0中最常用的新控件有下面5種。具體哪五種大家通過本文學(xué)習(xí)下
    2018-02-02
  • Android輕松畫出觸摸軌跡

    Android輕松畫出觸摸軌跡

    這篇文章主要為大家詳細(xì)介紹了Android輕松畫出觸摸軌跡的實(shí)現(xiàn)方法,為大家分享了一個(gè)觸摸軌跡類,感興趣的小伙伴們可以參考一下
    2016-03-03
  • Android自定義View實(shí)現(xiàn)風(fēng)車效果

    Android自定義View實(shí)現(xiàn)風(fēng)車效果

    這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)風(fēng)車效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Android仿抖音上下滑動(dòng)布局

    Android仿抖音上下滑動(dòng)布局

    這篇文章主要為大家詳細(xì)介紹了Android仿抖音上下滑動(dòng)布局,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12

最新評論