android 设置继承FragmentStatePagerAdapter(里面之间的传值)

1.adapter的设置

public class HomeWorkCorreactFragmentAdapter extends FragmentStatePagerAdapter {
private List list;// 所有题的集合(内部是一个个完整的题》》fragment)
private Activity activity;
private String  lessonId;
private String unitdirId;
private String answerStuId;
private String answerStuName;
public HomeWorkCorreactFragmentAdapter(FragmentManager fm, List list,String answerStuName,String answerStuId,String lessonId,String unitdirId, Activity activity) {
super(fm);
this.list = list;
this.activity = activity;
this.lessonId=lessonId;
this.unitdirId=unitdirId;
this.answerStuId=answerStuId;
this.answerStuName=answerStuName;
Log.d("answerStuId", "___adapter+answerStuId"+answerStuId);
}


@Override
public Fragment getItem(int position) {
return HomeWorkCorrectFragment.newInstance(list.get(position),answerStuName,answerStuId,lessonId,unitdirId,position);
}


@Override
public int getCount() {
return list.size();
}
}

2.HomeWorkCorrectFragment里面的设计


public class HomeWorkCorrectFragment extends Fragment {
private Activity activity;
public static int mNum;
private Context context;
private ExerciseBase exerciseSubjective;
private ImageView img_studentAnswer;
private String studentAnswerPath, studentBody, correctingAanswerPath, studentCorrectPath;
private Bitmap bmpDefaultPicStudent, bmpDefaultPicTeacher;
private static DisplayImageOptions displayOptions = DisplayImageOptions.createSimple();
private TextView tvPosition, tvPositionAll;
private LinearLayout linearLayout;
private ImageView img_student;
private LinearLayout linner_textchoose;
public static MediaPlayer mp;
private SeekBar seekBar;
private TextView tvView;
private TextView mediaplay_name;
private ImageButton ibtn_stop_start;
private Boolean bool = true;
private Thread mythread;
private int songLength;
private int iflag = 0;
private static int PIC_XC_NUM = 1;
private static int PIC_PZ_NUM = 2;
private String TAG="HomeWorkCorrectFragment";
private String datastr;//答题完成的时间
private Handler handlerTime = new Handler() {
public void handleMessage(Message msg) {
tvView.setText(msg.obj + "");
};
};
private LinearLayout lin_add;
private Button btn_submit;
private String stringJson;
private String lessonId;
private String unitdirId;
private String answerStuId;
private String answerStuName;


@SuppressLint("ValidFragment")
public static HomeWorkCorrectFragment newInstance(ExerciseBase dExerciseBean,String answerStuName,String answerStuId,String lessonId,String unitdirId, int num) {
HomeWorkCorrectFragment f = new HomeWorkCorrectFragment();
Bundle args = new Bundle();
args.putSerializable("dExerciseBean", dExerciseBean);
args.putInt("num", num);
args.putString("lessonId", lessonId);
args.putString("unitdirId", unitdirId);
args.putString("answerStuId", answerStuId);
args.putString("answerStuName", answerStuName);

f.setArguments(args);
return f;
}


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getActivity();
mNum = getArguments() != null ? getArguments().getInt("num") : 1;
lessonId=getArguments()!= null ? getArguments().getString("lessonId") : "";
unitdirId=getArguments()!= null ? getArguments().getString("unitdirId") : "";
answerStuId=getArguments()!= null ? getArguments().getString("answerStuId") : "";
answerStuName=getArguments()!= null ? getArguments().getString("answerStuName") : "";
exerciseSubjective = (ExerciseBase) (getArguments() != null ? getArguments().getSerializable("dExerciseBean") : null);
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home_work_correct, container, false);
linearLayout = (LinearLayout) view.findViewById(R.id.linerlayout_homework);
tvPosition = (TextView) view.findViewById(R.id.textview_position);
tvPositionAll = (TextView) view.findViewById(R.id.textview_position_all);
tvPosition.setText(mNum + 1 + "");// 显示正在做第几道题
tvPositionAll.setText("/" + BoyaConfig.exerciseNumAll);
// 初始化异步加载图片
/*ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
config.threadPriority(Thread.NORM_PRIORITY - 2);
config.denyCacheImageMultipleSizesInMemory();
config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
config.tasksProcessingOrder(QueueProcessingType.LIFO);
config.writeDebugLogs(); // Remove for release app
ImageLoader.getInstance().init(config.build());*/
return view;
}


@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
homeWorkCorrectView();//添加布局


}

………………

}

你可能感兴趣的:(Android)