Is my ListView onItemClickListener () not working when adding a WebView?
When I attach WebView
to ListView
, mine onItemClickListener()
from WebView
stops working. I know this is a focus issue WebView
. But I installed:
-
in xml
WebView
:android:clickable="false" android:focusable="false" android:focusableInTouchMode="false"
-
and also in the adapter class:
webview.setFocusable(false); webview.setFocusableInTouchMode(false); webview.versedata.setEnabled(false); webview.setClickable(false);
-
also in the main activity:
listview.setItemsCanFocus(false);
but mine onItemClickListener()
doesn't work. Any suggestions please?
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>
Try to implement in method setOnClickListener
in getView()
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;
}
Per this link, it turns out that list item list events will never be received for list items with views that can handle click events or can receive focus.
try inserting these two lines into the ACTIVITY (DO NOT ALLOW PROPERTIES IN OFFSET)
wv.setFocusable (false); wv.setClickable (false);