I am trying to create a horizontal scrollable set of web views using a gallery widget. The problem is that I cannot scroll through the views, which of course works for image galleries. Following the cookbook code, in onCreate () I activity:
g = (Gallery) findViewById(R.id.chapter_browser);
g.setAdapter(new WebViewAdapter(this));
The adapter then creates web views and returns them for the requested indexes:
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());
i.setLayoutParams(new Gallery.LayoutParams(100,100));
i.setInitialScale(100);
i.setFocusable(false);
i.setClickable(false);
return i;
}
}
The problem is that WebView insists on consuming touch events even though the attribute is clickabledisabled. I tried creating an OnTouchEventListener for the views and then sending the events to the gallery, but this is just a program crash.
Any hints appreciated.
source
share