大家好,我正在尝试在片段转换时设置进度条,我的第一个片段 onClick 调用第二个片段,这将在显示之前做一些繁重的工作。这项繁重的工作不使用 asynctask,因为它是从缓存中的 html 解析。
做这项工作的最佳方法是什么?
我的第一个片段:
private void onClick(final MoodleCourseContent[] courseContent,
View layout, final int contentIdx) {
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String courseId = Integer.toString(v.getId());
String courseName = courseContent[contentIdx].getName();
String topicId = (String) v.getTag();
Bundle bundle = new Bundle();
bundle.putString("courseId", courseId);
bundle.putString("courseName", courseName);
bundle.putString("topicId", topicId);
FragmentManager fragmentManager = getActivity()
.getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
FragTopics insideTopicsFrag = new FragTopics();
insideTopicsFrag.setArguments(bundle);
fragmentTransaction.addToBackStack(null);
fragmentTransaction
.replace(R.id.mainFragment, insideTopicsFrag);
fragmentTransaction.commit();
}
});
}....
我的第二个片段:
public class FragTopics extends Fragment {
Object course;
// ManSession Manager Class
ManSession session;
String courseId;
Long topicId;
String courseName;
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onViewCreated(view, savedInstanceState);
}
public FragTopics() {
}
@Override
public void onAttach(Activity activity) {
// TODO Auto-generated method stub
super.onAttach(activity);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
session = new ManSession(getActivity().getApplicationContext());
courseId = getArguments().getString("courseId");
topicId = Long.parseLong(getArguments().getString("topicId"));
courseName = getArguments().getString("courseName");
MoodleCourseContent[] courseTopics = new ManContents(getActivity()
.getApplicationContext()).getContent(courseId);
MoodleCourseContent singleTopic = new ManContents(getActivity()
.getApplicationContext()).getTopic(topicId, courseTopics);
return createTopics(singleTopic, courseName, courseId, topicId);
}......