Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6212373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:30:18+00:00 2026-05-24T06:30:18+00:00

I have created a custom listview that have one webview per element. My problem

  • 0

I have created a custom listview that have one webview per element.

My problem is that when I click on an element, it takes the bad element-positon.

Here is my custom listview

public class ListViewCustomAdapter extends BaseAdapter {
public ArrayList<String> mywebview;
public Activity context;
public LayoutInflater inflater;

public ListViewCustomAdapter(Activity context, ArrayList<String> mywebview) {
    //super();
    this.mywebview = new ArrayList<String>();
    this.context = context;
    this.mywebview = mywebview;
    this.inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
    return mywebview.size();
}

@Override
public String getItem(int position) {
    return mywebview.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

public static class ViewHolder {
    WebView mywebviewholder;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.mylistview2, null, false);
        holder.mywebviewholder = (WebView) convertView
                .findViewById(R.id.weblistview);

        holder.mywebviewholder
                .setOnTouchListener(new my.student.application.WebViewClickListener(
                        holder.mywebviewholder, parent, position));
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    holder.mywebviewholder.loadDataWithBaseURL("", mywebview.get(position)
            .toString(), "text/html", "UTF-8", "");
    return convertView;
}

my webview click listener

public class WebViewClickListener implements View.OnTouchListener {
private int position;
private ViewGroup vg;
private WebView wv;

public WebViewClickListener(WebView wv, ViewGroup vg, int position) {
    this.vg = vg;
    this.position = position;
    this.wv = wv;
}

public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_CANCEL:
        return true;
    case MotionEvent.ACTION_UP:
        sendClick();
        return true;
    }
    return false;
}

public void sendClick() {
    ListView lv = (ListView) vg;
    lv.performItemClick(wv, position, 0);
}

Thanks for your help

Edit: Something weird I found out. If in my listview.xml I change the height size of my webview, when I click on an element, It changes the position of the element

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:padding="3dip">
<WebView android:id="@+id/weblistview" android:layout_width="fill_parent"
    android:layout_height="200dip"></WebView>

With this heigh the order if I have 5 elements is: 2 1 0 2 1

I really don’t see where is the problem

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:30:19+00:00Added an answer on May 24, 2026 at 6:30 am

    In getView(), you are setting the touch listener to the view in the holder. That code only gets called for the first visible elements in the list (when convertView is null)

    You should be setting the listener to the current item right before returning the convertView so your code should look like this:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.mylistview2, null, false);
            holder.mywebviewholder = (WebView) convertView
                    .findViewById(R.id.weblistview);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mywebviewholder
                    .setOnTouchListener(new my.student.application.WebViewClickListener(
                            holder.mywebviewholder, parent, position));
        holder.mywebviewholder.loadDataWithBaseURL("", mywebview.get(position)
                .toString(), "text/html", "UTF-8", "");
        return convertView;
    }
    

    The idea with the holder is to avoid searching through the xml for every findViewByID.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom jQuery UI theme. One of my styles .ui-state-hover takes
I have a Custom ListView created from XML Layout. I want to bind that
I have created a small flash CS4 project that has a few custom components
I have an application that has created a number of custom event log sources
I have a custom listview row that contains a number of textView components. Instead
I created a listview that has a custom SimpleCursorAdapter. I want to place a
I have a ListView with a custom Adapter that creates rows containing TextViews that
I have a ListView with a custom list adapter (that extends BaseAdapter). My list
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I
I have created a custom dialog for Visual Studio Setup Project using the steps

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.