我正在尝试使用Gallery小部件构建一组水平滚动的webview.问题是我不能刷视图,这当然适用于图像库.遵循食谱代码,在活动的onCreate()I中:
g = (Gallery) findViewById(R.id.chapter_browser);
g.setAdapter(new WebViewAdapter(this));
Run Code Online (Sandbox Code Playgroud)
然后适配器创建webviews并返回它们以获取所请求的索引:
public class WebViewAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private String[] pages = {
"test1.html",
"test2.html",
"test3.html",
"test4.html"
};
public WebViewAdapter(Context c) {
mContext = c;
}
public int getCount() {
return pages.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
WebView i = new WebView(mContext);
i.loadUrl("file:///android_asset/" + pages[position]);
i.setBackgroundResource(mGalleryItemBackground);
i.setWebViewClient(new WebViewClient()); …Run Code Online (Sandbox Code Playgroud)