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

首頁 > 系統 > Android > 正文

Android開發入門之對話框簡單用法

2019-12-12 06:03:40
字體:
來源:轉載
供稿:網友

本文實例講述了Android開發入門之對話框簡單用法。分享給大家供大家參考,具體如下:

注:本文只是一個學習筆記 用以記錄自己學到哪了

1.獲得AlertDialog的靜態內部類Builder對象,由此類來創建對話框
2.通過Builder對象設置對話框的標題 按鈕以及按鈕響應的事件
3.調用Builder的Create()方法創建對話框
4.調用AlertDialog的show()方法顯示對話框

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"  ><TextView  android:id="@+id/MyTextView"  android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:text="@string/hello"  /><Button  android:id="@+id/myButton"  android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:text="創建Alert對話框"  /></LinearLayout>

MainActivity文件

@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    myTextView = (TextView)findViewById(R.id.MyTextView);    myButton = (Button)findViewById(R.id.myButton);    //添加AlertDialog.Builder對象    final AlertDialog.Builder builder = new AlertDialog.Builder(this);    //為activity中按鈕添加按鈕事件    myButton.setOnClickListener(new View.OnClickListener()    {    @Override    public void onClick(View v)    {      builder.setTitle("您確定要刪除此條信息?").      //設置確定按鈕      setPositiveButton("Yes", new OnClickListener()      {        @Override        public void onClick(DialogInterface dialog, int which)        {          myTextView.setText("刪除成功");        }      }).      //設置取消按鈕      setNegativeButton("No", new OnClickListener()      {        @Override        public void onClick(DialogInterface dialog, int which)        {          myTextView.setText("取消刪除");        }      });       //創建對話框        AlertDialog alertDialog = builder.create();        //顯示對話框        alertDialog.show();    }    });  }}

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android控件用法總結》、《Android資源操作技巧匯總》、《Android文件操作技巧匯總》、《Android操作SQLite數據庫技巧總結》、《Android操作json格式數據技巧總結》、《Android數據庫操作技巧總結》、《Android編程開發之SD卡操作方法匯總》、《Android開發入門與進階教程》、《Android編程之activity操作技巧總結》及《Android視圖View技巧總結

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇江市| 北京市| 怀柔区| 桃源县| 蕉岭县| 漳浦县| 新晃| 莎车县| 崇义县| 从江县| 紫阳县| 古交市| 平遥县| 深州市| 诸暨市| 长阳| 兴业县| 龙泉市| 延边| 涿州市| 衢州市| 扶风县| 莱阳市| 姚安县| 临汾市| 桐庐县| 恩平市| 高陵县| 漾濞| 银川市| 河间市| 阜新市| 肥乡县| 吴忠市| 靖安县| 凉城县| 怀仁县| 高邑县| 许昌市| 金堂县| 周至县|