我有 viewpager 和 asynctask 在一起。我正在毫无问题地显示内容。
但; 当我向页面添加单选按钮(用于多项选择题)时,在我在内容之间滑动后,之前选中的选项未选中。我想保存这个选中的选项
寻呼机适配器:
public class QuestionPagerAdapter extends PagerAdapter{
public QuestionPagerAdapter(){
super();
}
@Override
public int getCount() {
int qcount = QuestionPagerAdapter.q.getQuestionCount();
return qcount;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((View) object);
}
@Override
public Object instantiateItem(View collection, int pos) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//View v = null;
Context mycontext = collection.getContext();
View page = inflater.inflate(R.layout.page_quiz, null);
TextView tv = (TextView)page.findViewById(R.id.questionText);
FetchTask fft = new FetchTask(tv);
fft.execute(pos);
((ViewPager) collection).addView(page, 0);
return page;
}
@Override
public void destroyItem(View collection, int position, Object view) {
//Util.Log("destroying" + position);
((ViewPager) collection).removeView((View) view);
}
}
异步任务:
public class FetchTask extends AsyncTask<Integer, Void, ArrayList<String>> {
TextView outTxt;
public FetchTask(TextView outputTxt, LinearLayout linlay, RadioGroup mrg, Context dcontext) {
outTxt = outputTxt;
}
@Override
protected ArrayList<String> doInBackground(Integer... uri) {
ArrayList<String> result = new ArrayList<String>();
result.add(uri[0] + " " );
return result;
}
@Override
protected void onPostExecute(ArrayList<String> result) {
super.onPostExecute(result);
outTxt.setText(result.get(0));
}
}