Android 开发包:android-ActionQueue
ActionQueue 允许你一个一个的执行任务。
导入:
allprojects { repositories { mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots" } jcenter() } }
加依赖:
compile 'in.srain.cube:action-queue:1.0.1'
使用
创建 action:
String[] messageList = new String[]{ "message 1", "message 2", "message 3", }; for (int i = 0; i < messageList.length; i++) { String message = messageList[i]; PopDialogAction action = new PopDialogAction(message); mActionQueue.add(action); }
处理 action:
class PopDialogAction extends ActionQueue.Action<String> { public PopDialogAction(String badge) { super(badge); } @Override public void onAction() { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); Dialog dialog = builder.setMessage(getBadge()).show(); // notify action is done, and next aciton will be executed dialog.setOnDismissListener(mOnDismissListener); } }
action 执行完之后通知提醒:
DialogInterface.OnDismissListener mOnDismissListener = new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { mActionQueue.notifyActionDoneThenTryToPopNext(); } };
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!