![【移動應用開發(fā)技術】Android中怎么實現(xiàn)多種dialog_第1頁](http://file4.renrendoc.com/view/fee35187c2668a9b0b4fd5e72a5036fb/fee35187c2668a9b0b4fd5e72a5036fb1.gif)
![【移動應用開發(fā)技術】Android中怎么實現(xiàn)多種dialog_第2頁](http://file4.renrendoc.com/view/fee35187c2668a9b0b4fd5e72a5036fb/fee35187c2668a9b0b4fd5e72a5036fb2.gif)
![【移動應用開發(fā)技術】Android中怎么實現(xiàn)多種dialog_第3頁](http://file4.renrendoc.com/view/fee35187c2668a9b0b4fd5e72a5036fb/fee35187c2668a9b0b4fd5e72a5036fb3.gif)
![【移動應用開發(fā)技術】Android中怎么實現(xiàn)多種dialog_第4頁](http://file4.renrendoc.com/view/fee35187c2668a9b0b4fd5e72a5036fb/fee35187c2668a9b0b4fd5e72a5036fb4.gif)
下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
【移動應用開發(fā)技術】Android中怎么實現(xiàn)多種dialog
本篇文章為大家展示了Android中怎么實現(xiàn)多種dialog,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。string.xml文件源代碼:<resources>
<string
name="app_name">多種彈出對話框</string>
<string
name="dialog_img">圖片按鈕</string>
<string
name="dialog_radio">單選按鈕</string>
<string
name="dialog_box">復選按鈕</string>
<string
name="close">關閉</string>
</resources>布局文件源代碼:<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/img"
android:layout_height="100dp"
android:layout_width="100dp"
android:src="@drawable/aa"/>
<CheckBox
android:id="@+id/Checkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chinese"/>
<CheckBox
android:id="@+id/Checkbox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="English"
android:checked="true"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="復選按鈕確定"/>
<RadioGroup
android:id="@+id/radioGroup"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="male"
/>
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="female"/>
</RadioGroup>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="單選按鈕確定"/>
</LinearLayout>java文件源代碼:package
com.example.shiyan1_4;
import
android.app.Dialog;
import
android.content.DialogInterface;
import
android.preference.DialogPreference;
import
android.support.v7.app.AlertDialog;
import
android.support.v7.app.AppCompatActivity;
import
android.os.Bundle;
import
android.view.View;
import
android.widget.Button;
import
android.widget.CheckBox;
import
android.widget.EditText;
import
android.widget.ImageView;
import
android.widget.RadioButton;
import
android.widget.RadioGroup;
import
static
android.R.attr.id;
public
class
Shiyan1_4Activity
extends
AppCompatActivity
{
@Override
protected
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shiyan1_4);
ImageView
img
=
(ImageView)
findViewById(R.id.img);
Button
button1
=
(Button)
findViewById(R.id.button1);
Button
button2
=
(Button)
findViewById(R.id.button2);
img.setOnClickListener(new
View.OnClickListener()
{
@Override
public
void
onClick(View
v)
{
AlertDialog.Builder
dialog1
=
new
AlertDialog.Builder(Shiyan1_4Activity.this);
dialog1.setTitle(R.string.dialog_img)
.setMessage("您點擊了圖片按鈕!")
.setNegativeButton(R.string.close,
null)
.create()
.show();
}
});
button1.setOnClickListener(new
View.OnClickListener()
{
@Override
public
void
onClick(View
v)
{
AlertDialog.Builder
dialog1
=
new
AlertDialog.Builder(Shiyan1_4Activity.this);
String
str1
=
"";
//獲取復選按鈕的值
CheckBox
Checkbox1
=
(CheckBox)findViewById(R.id.Checkbox1);
if(Checkbox1.isChecked()){
str1
+=
Checkbox1.getText()
+
"is
selected
!";
}
CheckBox
Checkbox2
=
(CheckBox)findViewById(R.id.Checkbox2);
if(Checkbox2.isChecked()){
str1
+=
Checkbox2.getText()
+
"
is
selected
!\n";
}
dialog1.setTitle(R.string.dialog_box)
.setMessage(str1)
.setNegativeButton(R.string.close,
null)
.create()
.show();
}
});
button2.setOnClickListener(new
View.OnClickListener()
{
@Override
public
void
onClick(View
v)
{
AlertDialog.Builder
dialog2
=
new
AlertDialog.Builder(Shiyan1_4Activity.this);
String
str2
=
"";
//獲取單選按鈕的值
RadioGroup
radioGroup
=
(RadioGroup)findViewById(R.id.radioGroup);
for
(int
i
=
0;
i
<radioGroup.getChildCount();
i++){
RadioButton
radioButton
=
(RadioButton)
radioGroup.getChildAt(i);
if(radioButton.isChecked()){
str2
+=
radioButton.getText()
+
"
is
selected
!";
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 校園欺凌現(xiàn)象與法律應對措施
- DB3715T 72-2025楊柳飛絮綜合防治技術規(guī)程
- 中外工程技術許可合同范例
- OEM技術合作合同(微機領域)
- 個人臨時借款合同范本
- 中外合資企業(yè)土地使用權轉(zhuǎn)讓協(xié)議合同
- 臨海市農(nóng)產(chǎn)品供需雙方種植收購合同
- 書法教育合作協(xié)議合同
- 個人租車服務合同范本
- 二手商場租賃合同范本
- 2024年05月浙江金華成泰農(nóng)商銀行員工招考筆試歷年參考題庫附帶答案詳解
- 北京市海淀區(qū)2024-2025學年七年級上學期期末考試數(shù)學試題(含答案)
- 帶看協(xié)議書范本(2篇)
- 股權投資項目建議書
- 2025年北京廣播電視臺招聘(140人)歷年高頻重點提升(共500題)附帶答案詳解
- 2024復工復產(chǎn)安全培訓
- 中學生宿舍日常與管理
- 【歷史】秦漢時期:統(tǒng)一多民族國家的建立和鞏固復習課件-2024-2025學年統(tǒng)編版七年級歷史上冊
- 社區(qū)中心及衛(wèi)生院65歲及以上老年人健康體檢分析報告模板
- 化工過程安全管理導則AQT 3034-2022知識培訓
- 第02講 導數(shù)與函數(shù)的單調(diào)性(教師版)-2025版高中數(shù)學一輪復習考點幫
評論
0/150
提交評論