Reputation: 553
I have a listview with a custom adapter for each item of the list. If my custom item is some textview everything works fine. But each item has to be some html and hence I need each item to be a webview. The problem is that the webview steals my click and thus I cannot select an item from the list anymore.
So this:
this.itemAdapter = new ItemAdapter(this, R.layout.webview, itemArrayList);
ListView lv1 = (ListView) findViewById(R.id.ListView01);
lv1.setOnItemClickListener( new ItemSelected());
lv1.setAdapter(this.itemAdapter);
public class ItemSelected implements OnItemClickListener
{
@Override
public void onItemClick(AdapterView av, View v, int item, long id)
{
Intent showTextIntent = new Intent(showItems, ShowItemDetails.class);
showTextIntent.putExtra("itemID", singleItems.get(item).getItemID());
startActivity(showTextIntent);
}
}
click is dead. I don't have any link in the webview or have to navigate I only use it to have a nice formatted text (fromHtml for the textview is not that nice). Any chance?
Upvotes: 2
Views: 5950
Reputation: 5050
I've found two ways to achieve it:
1: Set a touch listener on the WebView to redirect the touch event
webView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
// Do your thing
}
return false;
}
});
2: Avoid all possible touch events from being fired
webView.setClickable(false);
webView.setLongClickable(false);
webView.setFocusable(false);
webView.setFocusableInTouchMode(false);
Upvotes: 1
Reputation: 51
Setting the webviews attributes clickable and focusable to false worked for me. Doing that ListView's OnItemClickListener was firing again.
Upvotes: 0
Reputation: 200100
Try to do setClickable(false)
in your WebView
, or use android:clickable="false"
on the XML layout.
Upvotes: 2