大家好我在这里,因为我已经尝试了几乎所有东西,因为在Asynctask中运行片段事务或者在一个新线程中似乎没有任何工作,我自己无法弄明白。
我尝试了什么:
和其他人
我的问题:
我的主要内容:
Bundle bundle = getIntent().getExtras();
FragmentTransaction fragmentTransaction = getFragmentManager()
.beginTransaction();
FragTopics insideTopicsFrag = new FragTopics();
insideTopicsFrag.setArguments(bundle);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.replace(R.id.mainFragment, insideTopicsFrag);
fragmentTransaction.commit();
我的片段: createTopics返回包含所有内容的视图,换句话说,它是过去在onCreateView中返回的视图。
public class FragTopics extends Fragment {
View v;
public FragTopics() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = new View(getActivity());
new TopicsAsyncTask().execute();
return v;
}
private class TopicsAsyncTask extends AsyncTask<Void, Void, Boolean> {
ManSession session;
String courseId;
Long topicId;
String courseName;
MoodleCourseContent[] courseTopics;
MoodleCourseContent singleTopic;
private final ProgressDialog dialog = new ProgressDialog(getActivity());
@Override
protected void onPreExecute() {
this.dialog.setMessage("loading...");
this.dialog.show();
}
@Override
protected Boolean doInBackground(Void... params) {
ObtainData();
return true;
}
@Override
protected void onPostExecute(Boolean result) {
this.dialog.dismiss();
// The createTopics returns the View with all contents
v = createTopics(singleTopic, courseName, courseId, topicId);
}
}
答案 0 :(得分:0)
将您的onCreateView
更改为:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = new View(getActivity());
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
new TopicsAsyncTask().execute();
}
}, 200);
return v;
}
希望它仍有帮助