Reputation: 83
When I attach WebView
to ListView
then my onItemClickListener()
of WebView
stops working. I know that this is problem of focus of WebView
. But I set:
in xml of WebView
:
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
as well as in adapter class:
webview.setFocusable(false);
webview.setFocusableInTouchMode(false);
webview.versedata.setEnabled(false);
webview.setClickable(false);
also in main activity:
listview.setItemsCanFocus(false);
but still my onItemClickListener()
is not working. Any suggestions please?
Upvotes: 3
Views: 1468
Reputation: 443
to add your xml main layout
android:descendantFocusability="blocksDescendants"
Example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:auto="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<WebView
android:layout_width="fill_parent"`
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Upvotes: 1
Reputation: 1036
According to this link,It turns out that list item click events will never be received for list items with views that can either handle click events or can gain focus.
try inserting these two lines in the ACTIVITY(DONT PUT THE PROPERTIES IN THE LAYOUT)
wv.setFocusable(false); wv.setClickable(false);
Upvotes: 0
Reputation: 1285
Try to implement setOnClickListener
in getView()
method of in the class derived from BaseAdapter class
public View getView(int position, View convertView, ViewGroup parent)
{
convertView.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//your code
}
});
return convertView;
}
Upvotes: 0