最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android單選按鈕對話框用法實例分析

 更新時間:2015年09月15日 11:28:43   作者:Ruthless  
這篇文章主要介紹了Android單選按鈕對話框用法,以完整實例形式分析布局及對話框類的相關(guān)使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了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("單選按鈕對話框");
      //0: 默認(rèn)第一個單選按鈕被選中
      builder.setSingleChoiceItems(R.array.hobby, 0, new OnClickListener(){
        public void onClick(DialogInterface dialog, int which) {
          String hoddy=getResources().getStringArray(R.array.hobby)[which];
          editText.setText("您選擇了: "+hoddy);
        }
      });
      //添加一個確定按鈕
      builder.setPositiveButton(" 確 定 ", new DialogInterface.OnClickListener(){
        public void onClick(DialogInterface dialog, int which) {
        }
      });
      //創(chuàng)建一個單選按鈕對話框
      dialog=builder.create();
      break;
    }
    return dialog;
  }
}

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

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

相關(guān)文章

  • 在android中ScrollView嵌套ScrollView解決方案

    在android中ScrollView嵌套ScrollView解決方案

    大家好,眾所周知,android里兩個相同方向的ScrollView是不能嵌套的,那要是有這樣的需求怎么辦,接下來為您介紹解決方法,感興趣的朋友可以了解下
    2013-01-01
  • Android自定義View實現(xiàn)五子棋小游戲

    Android自定義View實現(xiàn)五子棋小游戲

    這篇文章主要為大家詳細(xì)介紹了Android自定義View實現(xiàn)五子棋小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android中監(jiān)聽短信的兩種方法

    Android中監(jiān)聽短信的兩種方法

    這篇文章主要介紹了Android中監(jiān)聽短信的兩種方法,本文講解了監(jiān)聽廣播、采用觀察方法,監(jiān)聽短信數(shù)據(jù)庫兩種方法,需要的朋友可以參考下
    2015-04-04
  • 最新評論

    韶山市| 行唐县| 武陟县| 高雄县| 密山市| 亚东县| 景德镇市| 靖西县| 普兰店市| 浦东新区| 保亭| 抚州市| 宽城| 丰县| 大石桥市| 上虞市| 德化县| 二手房| 东丽区| 云林县| 临颍县| 石城县| 祁门县| 抚顺市| 庆城县| 句容市| 鄂伦春自治旗| 舟山市| 临武县| 佳木斯市| 容城县| 托克托县| 乃东县| 靖江市| 时尚| 砀山县| 盐亭县| 平陆县| 资阳市| 潼关县| 灌云县|