Android dialog应用经验总结

移动开发 Android
我们在这里将会为大家详细介绍一下有关Android dialog的实现方法。大家可以通过我们在这里介绍的内容充分掌握这一应用技巧。

Android手机操作系统是一款由谷歌推出的开源操作系统。在智能手机领域中,这一操作系统占据着非常重要的地位。在这里我就先来了解一下Android dialog的实现方法。希望可以给大家带来一些帮助。#t#

1、网上说的很多,Android dialog实现的方法有两个

一个是通过AlertDialog.Builder 初始化dialog 然后再showDialog

另一个是通过将androidManifest.xml中的activity的属性设为android:theme="@android:style/Theme.Dialog,伪装为dialog

2、showDialog的线程问题

Android dialog的显示不会阻塞ui线程.....

例子

Java代码

protected void onListItemClick(ListView l, View v, 
int position, long id) {   
Intent intent = new Intent();    Bundle bundle = new Bundle();    switch (editMode) {    case SELECT:    bundle.putString("listName", list.get
(position).getName());   
intent.setClass(this, AudioPlayer.class);    intent.putExtras(bundle);    startActivity(intent);    break;    case RENAME:    oldName = list.get(position).getName();    intent.setClass(MusicList.this, DialogActivity.class);    startActivityForResult(intent, Preferences.RENAME);    break;    case DELETE:    oldName = list.get(position).getName();    showDialog(CONFIRM_DIALOG);    delete(oldName,flag);    break;    }    editMode = EditMode.SELECT;    protected Dialog onCreateDialog(int id) {    switch (id) {    case CONFIRM_DIALOG:    return new AlertDialog.Builder(MusicList.this).setIcon(    android.R.drawable.ic_dialog_alert).setTitle("确认删除?")    .setPositiveButton(R.string.confirm,    new DialogInterface.OnClickListener() {    public void onClick(DialogInterface dialog,    int whichButton) {    mListTool.deleteList(oldName);    flag = true;    }    }).setNegativeButton(R.string.cancel,    new DialogInterface.OnClickListener() {    public void onClick(DialogInterface dialog,    int whichButton) {    flag = false;    }    }).create();    }    return null;    } }    protected void onListItemClick(ListView l, View v, 
int position, long id) {  
Intent intent = new Intent();   Bundle bundle = new Bundle();   switch (editMode) {   case SELECT:   bundle.putString("listName", list.get(position).getName());   intent.setClass(this, AudioPlayer.class);   intent.putExtras(bundle);   startActivity(intent);   break;   case RENAME:   oldName = list.get(position).getName();   intent.setClass(MusicList.this, DialogActivity.class);   startActivityForResult(intent, Preferences.RENAME);   break;   case DELETE:   oldName = list.get(position).getName();   showDialog(CONFIRM_DIALOG);   delete(oldName,flag);   break;   }   editMode = EditMode.SELECT;   protected Dialog onCreateDialog(int id) {   switch (id) {   case CONFIRM_DIALOG:   return new AlertDialog.Builder(MusicList.this).setIcon(   android.R.drawable.ic_dialog_alert).setTitle("确认删除?")   .setPositiveButton(R.string.confirm,   new DialogInterface.OnClickListener() {   public void onClick(DialogInterface dialog,   int whichButton) {   mListTool.deleteList(oldName);   flag = true;   }   }).setNegativeButton(R.string.cancel,   new DialogInterface.OnClickListener() {   public void onClick(DialogInterface dialog,   int whichButton) {   flag = false;   }   }).create();     }   return null;   } } 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.

Android dialog的对话框还在初始化得过程中,delete方法就调用了,说明dialog是另开一个线程的,同时提供回调方法

3、取得dialog中Edittext的内容问题

由于Android dialog本身没有提供取得Edittext内容的回调函数,所以需要自己写.....

简单的方法是使用activity伪装dialog,有布局更自由,消息传递更方便地优点

责任编辑:曹凯 来源: javaeye.com
相关推荐

2010-01-25 14:25:33

Android Int

2009-11-17 11:24:00

PHP应用技巧

2010-01-26 13:28:11

Android开发要点

2017-02-17 11:19:00

Android内存泄露分析总结

2009-12-31 10:21:53

Silverlight

2010-05-06 17:30:56

Oracle查询语句

2009-10-15 09:27:00

2010-02-02 15:44:18

C++遍历集合

2009-10-27 10:46:27

ADSL接入技术

2010-01-06 15:52:11

软交换技术

2009-08-19 09:24:43

AJAX引擎经验总结

2009-09-29 16:32:11

OJB Hiberna

2010-01-25 13:37:07

Android传感器

2009-09-16 17:13:54

学习Linq

2010-09-13 10:52:37

CSS定位

2010-04-28 17:14:38

Oracle EXPL

2009-10-23 09:43:44

光纤接入网

2009-09-25 17:26:55

使用Hibernate

2009-09-27 14:53:38

Hibernate S

2010-03-08 15:12:27

Python语言
点赞
收藏

51CTO技术栈公众号