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 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!