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

Android開發(fā)入門之對話框簡單用法

 更新時(shí)間:2016年07月08日 16:01:03   作者:manymore13  
這篇文章主要介紹了Android對話框簡單用法,涉及Android對話框的功能、定義、創(chuàng)建及使用等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

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

注:本文只是一個(gè)學(xué)習(xí)筆記 用以記錄自己學(xué)到哪了

1.獲得AlertDialog的靜態(tài)內(nèi)部類Builder對象,由此類來創(chuàng)建對話框
2.通過Builder對象設(shè)置對話框的標(biāo)題 按鈕以及按鈕響應(yīng)的事件
3.調(diào)用Builder的Create()方法創(chuàng)建對話框
4.調(diào)用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="創(chuàng)建Alert對話框"
  />
</LinearLayout>

MainActivity文件

@Override
public 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("您確定要?jiǎng)h除此條信息?").
      //設(shè)置確定按鈕
      setPositiveButton("Yes", new OnClickListener()
      {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
          myTextView.setText("刪除成功");
        }
      }).
      //設(shè)置取消按鈕
      setNegativeButton("No", new OnClickListener()
      {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
          myTextView.setText("取消刪除");
        }
      });
       //創(chuàng)建對話框
        AlertDialog alertDialog = builder.create();
        //顯示對話框
        alertDialog.show();
    }
    });
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android資源操作技巧匯總》、《Android文件操作技巧匯總》、《Android操作SQLite數(shù)據(jù)庫技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進(jìn)階教程》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》及《Android視圖View技巧總結(jié)

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

相關(guān)文章

最新評論

丹凤县| 太谷县| 闽侯县| 绥化市| 增城市| 康定县| 泸州市| 宜川县| 津南区| 沾益县| 黔南| 临夏县| 博湖县| 惠水县| 夹江县| 秭归县| 永年县| 永顺县| 静海县| 长丰县| 萨嘎县| 台州市| 庄浪县| 富阳市| 洱源县| 上饶市| 萨迦县| 鄂伦春自治旗| 且末县| 阿鲁科尔沁旗| 吴旗县| 陵水| 焉耆| 偏关县| 宁明县| 保山市| 弥渡县| 荣成市| 翼城县| 太白县| 鲁山县|