DEVENDRA
DEVENDRA

Reputation: 83

My ListView's onItemClickListener() not working when adding WebView?

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:

but still my onItemClickListener() is not working. Any suggestions please?

Upvotes: 3

Views: 1468

Answers (3)

user3068659
user3068659

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

Rajesh Wadhwa
Rajesh Wadhwa

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

Mohit Mehta
Mohit Mehta

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

Related Questions