安卓開發5 AlertDialog的使用

2022-08-31 22:12:19 字數 2260 閱讀 3048

新建android xml layout file

new – android – android xml layout file – 名稱為「layout_set」,實現oa的訪問位址、是否需要提醒、是否需要聲音提醒、振動提醒等設定。這裡我用了乙個tablelayout,加入乙個edittext和3個checkbox。**如下:

android:id="@+id/tablelayout1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:id="@+id/textview1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="登陸**" />

android:id="@+id/edittext_url"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ems="10" >

android:id="@+id/checkbox_alert"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="有訊息是否提醒" />

android:id="@+id/checkbox_vibrate"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="振動提醒" />

android:id="@+id/checkbox_sound"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="聲音提醒" />

這裡將用alertdialog方式開啟,不需要增加button。

開啟alertdialog

在選單onoptionsitemselected的「設定」部分增加開啟的**,並實現讀取edittext和checkbox的值,採用sharedpreferences儲存。checkbox是否被選中用ischecked() ,選中用setchecked(boolean)。alertdialog的建立**如下,其中「layout_set」是我建立的布局檔名稱,「tablelayout1」是布局檔案的layout id。為了能在「確定」的onclicklistener匿名內部類中呼叫外部變數dialoglayout,dialoglayout需要用final修飾.

layoutinflater inflater = getlayoutinflater();

final view dialoglayout = inflater.inflate(r.layout.layout_set, (viewgroup)findviewbyid(r.id.tablelayout1));

new alertdialog.builder(this).settitle("設定").setview(dialoglayout)

.setpositivebutton("確定", new onclicklistener()

}).setegativebutton("取消", null).show();

關於alertdialog

我曾經嘗試在alertdialog.builder builder = new alertdialog.builder(this);之後,一口氣加完settitle、setmessage、setview(edittext)、setmultichoiceitems、setsinglechoiceitems、setitems,結果只出現edittext,而沒有單選多選,研究後發現在 alertdialog中setmessage、setmultichoiceitems等只能乙個有效,因此複雜的互動內容只能用setview的自定義布局方式。

bluetooth spp安卓開發

在開發有關android的藍芽spp服務時,發現了一點問題,需要注意的是,在連線spp服務的時候,有可能直接呼叫connect會出現exception的問題,因此,對於spp的服務應當有兩種實現比較保險,spp的服務特徵碼 uuid 00001101 0000 1000 8000 00805f9b3...

安卓相機開發

隨著手機效能的提高,多 的應用越來越普遍,其中拍照,錄影,美顏等都需要呼叫手機相機的功能。相機採集和顯示的經典例子是下面谷歌的開源實現,是比較好的入門學習資料 網上有很多開源的安卓相機的實現,比如下面的實現,只是時間比較久了 比較新的是下面的實現,它封裝了gpuimage來進行濾鏡和美顏的處理 還有...

Unity 安卓開發

不過不要慌,如果你不想用最新版本也可以這麼幹 1.安裝個最新版本的編輯器並在安裝時勾選android build support那些選項。2.完成安裝後開啟編輯器找到配置的路徑 edit preferences external tools 直接把這些路徑拷貝到你想要用的那個版本編輯器配置。打包ap...