android dialog小结
16lz
2021-01-23
1、网上说的很多,android实现dialog的方法有两个
- 一个是通过AlertDialog.Builder 初始化dialog 然后再showDialog
- 另一个是通过将androidManifest.xml中的activity的属性设为android:theme="@android:style/Theme.Dialog,伪装为dialog
2、showDialog的线程问题
dialog的显示不会阻塞ui线程.....
例子
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;}}
dialog的对话框还在初始化得过程中,delete方法就调用了,说明dialog是另开一个线程的,同时提供回调方法
然两个线程通信
3、取得dialog中Edittext的内容问题
由于dialog本事没有提供取得Edittext内容的回调函数,所以需要自己写.....
简单的方法是使用activity伪装dialog,有布局更自由,消息传递更方便地优点
更多相关文章
- 常用的小方法,避免忘记,在此记录一下
- Android中获取颜色的几种方法
- android中View.measure方法详解
- Android SDK下载和更新失败的解决方法
- Android代码混淆官方实现方法
- android绑定服务方法使用
- Android学习札记18:Drawable中的setDither()方法
- Android 获取WIFI MAC地址的方法
- Android 多线程之线程池