(一)Dialog簡(jiǎn)介
成都創(chuàng)新互聯(lián)公司主營(yíng)紹興網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,App定制開發(fā),紹興h5重慶小程序開發(fā)搭建,紹興網(wǎng)站營(yíng)銷推廣歡迎紹興等地區(qū)企業(yè)咨詢Dialog是Android開發(fā)中需要經(jīng)常使用的系統(tǒng)組件之一,AlertDialog可以顯示一個(gè)、兩個(gè)等多個(gè)按鈕,使用setMessage()方法可以只顯示字符串提示信息,當(dāng)然用戶也可以自定義自己的AlertDialog。
構(gòu)造方法

更改主題

2. 常用方法

(二)代碼實(shí)現(xiàn)
MainActivity代碼
package com.example.mydialog;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
private ArrayList<HashMap<String, Object>> listItem;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
openDialog();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void openDialog() {
new AlertDialog.Builder(MainActivity.this).setTitle("自定義Dialog")
.setIcon(R.drawable.albums)
.setAdapter(getAdaper(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
// 獲取選中項(xiàng)的內(nèi)容
Log.d("測(cè)試", listItem.get(which).get("ItemManager")
.toString());
}
}).show();
}
public ListAdapter getAdaper() {
listItem = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> map1 = new HashMap<String, Object>();
map1.put("ImageManager", R.drawable.compose);
map1.put("ItemManager", "錄入");
listItem.add(map1);
HashMap<String, Object> map2 = new HashMap<String, Object>();
map2.put("ImageManager", R.drawable.camera);
map2.put("ItemManager", "拍照");
listItem.add(map2);
HashMap<String, Object> map4 = new HashMap<String, Object>();
map4.put("ImageManager", R.drawable.delete1);
map4.put("ItemManager", "刪除");
listItem.add(map4);
SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem,
R.layout.mydialog,
new String[] { "ImageManager", "ItemManager" }, new int[] {
R.id.p_w_picpath, R.id.text });
return listItemAdapter;
}
}
mydialog.xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center_vertical"
>
<ImageView android:id="@+id/p_w_picpath"
android:layout_width="38dp"
android:layout_height="38dp"
/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical ="true"
android:textColor="#000000" />
</RelativeLayout>效果如下:

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
本文題目:Android之自定義AlertDialog的實(shí)現(xiàn)方法(一)-創(chuàng)新互聯(lián)
當(dāng)前URL:http://chinadenli.net/article44/cddehe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、商城網(wǎng)站、網(wǎng)站內(nèi)鏈、App設(shè)計(jì)、營(yíng)銷型網(wǎng)站建設(shè)、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)