我一直在使用 viewpageAdapter,但是当我尝试用新内容更新它时,它似乎没有更新。但我正在从数据库中获取该内容。
这是我的 ViewpagerAdapter 类
public class ViewpagerAdapter extends PagerAdapter {
Context context;
ViewPager pager;
public ViewpagerAdapter(Context ctx, ArrayList<String> list) {
this.context = ctx;
fullPr=list;
// TODO Auto-generated constructor stub
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return fullPr.size();
}
@Override
public void notifyDataSetChanged() {
// System.out.println("notifyDataSetChanged()");
// TODO Auto-generated method stub
super.notifyDataSetChanged();
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
// TODO Auto-generated method stub
return arg0 == ((View) arg1);
}
@Override
public Object instantiateItem(View container, int position) {
// TODO Auto-generated method stub
WebView wb = new WebView(context);
wb.setBackgroundColor(Color.parseColor("#F5EBC6"));
wb.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
// TextView wb=new TextView(context);
wb.getSettings().setBuiltInZoomControls(true);
wb.setPadding(10, 10, 10, 10);
((ViewPager) container).addView(wb, 0);
String yourhtmlpage = "<html><body>" + fullPr.get(position)
+ "</body></html>";
wb.loadDataWithBaseURL(null, yourhtmlpage, "text/html", "UTF-8",
null);
return wb;
}
@Override
public Parcelable saveState() {
// TODO Auto-generated method stubmatch_parent
return null;
}
@Override
public void destroyItem(View container, int position, Object object) {
// TODO Auto-generated method stub
((ViewPager) container).removeView((View) object);
}
}
这是 onclick 函数,我用它来将新页面内容传递到适配器。这里的 notifyDataSetChanged 没有改变内容。
public void onClick(DialogInterface dialog, int item) {
chooselangDesc = db.rawQuery("SELECT ZCON FROM ZPR WHERE
ZPR1='"+ passLagID1 + "' AND ZLANGUAGE='"+ realLanguageID[item] + "'", null);
if (chooselangDesc.moveToFirst()) {
prbyLang.add(chooselangDesc.getString(chooselangDesc
.getColumnIndex("ZCONTENT")));
fullPr=null;
fullPr=prbyLang;
adapter_content = new ViewpagerAdapter(getApplicationContext(), fullPr);
myPager.setAdapter(adapter_content);
adapter_content.notifyDataSetChanged();
}
dialog.cancel();
}