【发布时间】:2017-04-02 04:51:07
【问题描述】:
在我的活动中,如何让我的 for 循环暂停以调用片段。按钮上的内部片段单击如何返回活动并恢复循环以再次启动该过程。
我在活动中的一段代码在循环中启动片段
for(int i = 0; i < lQuestModels.size(); i++){
StartMyFragment start_survey=new StartMyFragment();
Bundle bundle = new Bundle();
bundle.putString("survey_id", "111");
bundle.putString("survey_name", "testing");
bundle.putString("survey_desc", "Yes done");
bundle.putString("survey_no_of_question", "5");
bundle.putString("jListString", lQuestModels.get(i).toString());
start_survey.setArguments(bundle);
fragmentManager = getSupportFragmentManager();
fragmentManager.popBackStack();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.welcomeSurveyLayout,start_survey);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
【问题讨论】:
-
是的,您可以这样做,但在我们帮助您之前,您必须展示您已经尝试过的内容。
-
我是 android 片段和活动通信的新手。无法想象循环将如何在 Activity 和 Fragment 之间暂停和继续。
-
使用处理程序概念做到了,这是UI和后台进程之间最好的沟通方式
标签: android android-activity fragment