网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Android之自定义AlertDialog的实现方法(一)

(一)Dialog简介

10年积累的成都做网站、网站制作、成都外贸网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有同德免费网站建设让你可以放心的选择与我们合作。

   Dialog是Android开发中需要经常使用的系统组件之一,AlertDialog可以显示一个、两个等多个按钮,使用setMessage()方法可以只显示字符串提示信息,当然用户也可以自定义自己的AlertDialog。

  1. 构造方法

   Android之自定义AlertDialog的实现方法(一)

更改主题

Android之自定义AlertDialog的实现方法(一)

2.  常用方法

Android之自定义AlertDialog的实现方法(一)

(二)代码实现

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> 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
// 获取选中项的内容
Log.d("测试", listItem.get(which).get("ItemManager")
.toString());
}
}).show();
}
public ListAdapter getAdaper() {
listItem = new ArrayList>();
HashMap map1 = new HashMap();
map1.put("ImageManager", R.drawable.compose);
map1.put("ItemManager", "录入");
listItem.add(map1);
HashMap map2 = new HashMap();
map2.put("ImageManager", R.drawable.camera);
map2.put("ItemManager", "拍照");
listItem.add(map2);
HashMap map4 = new HashMap();
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文件


    

    

效果如下:

Android之自定义AlertDialog的实现方法(一)


分享标题:Android之自定义AlertDialog的实现方法(一)
网站链接:http://bjjierui.cn/article/ihhhjj.html

其他资讯