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 6165899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:14:47+00:00 2026-05-23T22:14:47+00:00

I am having a confusing problem with my listview in android. I get my

  • 0

I am having a confusing problem with my listview in android. I get my list populated from a database, and these results need to be filtered based on given criteria. A default list is shown, then the list can be filtered based on the particular button that is pushed. All of this filtering is happening properly. My problem starts when I click on one of the items in the list. The position is not being returned correctly(I am checking this by using Toast.makeText(this,” ” + position, Toast.LENGTH_SHORT).show();)

I have posted the code I believe may be relevant to the problem. Any help would be great!

@Override
public void onClick(View v) {
    switch(v.getId()){ 
    case R.id.search:
        Intent i = new Intent(v.getContext(), SearchScreen.class);
        startActivityForResult(i, 0);
        break;
    case R.id.directory:  

        break;  
    case R.id.todo:  
        Intent i1 = new Intent(v.getContext(), ToDoScreen.class);
        startActivityForResult(i1, 0);

        break;   
    case R.id.favorites:
        Intent i2 = new Intent(v.getContext(), FavsScreen.class);
        startActivityForResult(i2, 0);

        break;
    case R.id.coupon:
        Intent i3 = new Intent(v.getContext(), CouponScreen.class);
        startActivityForResult(i3, 0);

        break;
    case R.id.info:
        Intent i4 = new Intent(v.getContext(), InfoScreen.class);
        startActivityForResult(i4, 0);

        break;
    case R.id.creative:
        countybar.setVisibility(View.VISIBLE);
        business.setChamber(0);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.downtown:
        countybar.setVisibility(View.GONE);
        business.setChamber(1);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.chamber:
        countybar.setVisibility(View.VISIBLE);
        business.setChamber(2);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.all:
        business.setCounty(0);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.cayuga:
        business.setCounty(1);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.cortland:
        business.setCounty(2);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.herkimer:
        business.setCounty(3);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.jefferson:
        business.setCounty(4);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.lewis:
        business.setCounty(5);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.madison:
        business.setCounty(6);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.monroe:
        business.setCounty(7);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.oneida:
        business.setCounty(8);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.onondaga:
        business.setCounty(9);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.oswego:
        business.setCounty(10);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.seneca:
        business.setCounty(11);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.lawrence:
        business.setCounty(12);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.tompkins:
        business.setCounty(13);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;
    case R.id.yates:
        business.setCounty(14);
        category = business.filterCategoryString();
        adap.notifyDataSetChanged();

        break;



    }



}




@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    Toast.makeText(this, category.elementAt(position) + position + "  onListItemClick", Toast.LENGTH_SHORT).show();
    business.setCategory(category.elementAt(position));
}

public static class EfficientAdapter extends BaseAdapter implements Filterable {
private LayoutInflater mInflater;
private Context context;

public EfficientAdapter(Context context) {
// Cache the LayoutInflate to avoid asking for a new one each time.
mInflater = LayoutInflater.from(context);
this.context = context;
}

/**
* Make a view to hold each row.
*
* @see android.widget.ListAdapter#getView(int, android.view.View,
*      android.view.ViewGroup)
*/
public View getView(final int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid
// unneccessary calls
// to findViewById() on each row.
    ViewHolder holder;

// When convertView is not null, we can reuse it directly, there is
// no need
// to reinflate it. We only inflate a new View when the convertView
// supplied
// by ListView is null.
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.list_items, null);

// Creates a ViewHolder and store references to the two children
// views
// we want to bind data to.
        holder = new ViewHolder();
        holder.textLine = (TextView) convertView.findViewById(R.id.textLine);
        holder.iconLine = (ImageView) convertView.findViewById(R.id.rightarrow);


        convertView.setOnClickListener(new OnClickListener() {
            private int pos = position;

            @Override
            public void onClick(View v) {
                Toast.makeText(context, category.elementAt(pos) + pos + "  On Click", Toast.LENGTH_SHORT).show();   
                business.setCategory(category.elementAt(pos));
                Intent intent = new Intent(v.getContext(), ListingScreen.class);
                context.startActivity(intent);
            }
        });


        convertView.setTag(holder);
    } else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
        holder = (ViewHolder) convertView.getTag();
    }

// Bind the data efficiently with the holder.
    holder.textLine.setText(category.elementAt(position));

    return convertView;
}

static class ViewHolder {
    TextView textLine;
    ImageView iconLine;
    Button buttonLine;
}

@Override
public android.widget.Filter getFilter() {
// TODO Auto-generated method stub
    return null;
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
    return 0;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
    return category.size();
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
    return category.elementAt(position);
}
  • 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-23T22:14:47+00:00Added an answer on May 23, 2026 at 10:14 pm

    Make use of the formula:

    wantedPos = position - listView.getFirstVisiblePosition()
    

    😉

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

Sidebar

Related Questions

I'm having a really confusing problem. I have a UIWebView that is contained within
I'm having a problem with naming a method for a database application. In my
I'm having a problem and believe something simple, just can't get a grip on
I am having a very confusing problem with an application I have been working
I'm having a pretty confusing problem in building a binary tree. Apparently this should
I'm having a problem with my shader loading code. The bizarre thing that's confusing
Well, sorry about the confusing title but I'm having a slightly annoying problem with
I'm having a problem calling an outside application from a compiled ocaml application, pdflatex.
I'm having the problem described here: http://groups.google.com/group/microsoft.public.xml.soap/browse_thread/thread/029ee5b5d4fa2440/0895d73c5c3720a1 I am consuming a Web Service using
I'm having a very confusing error between SharePoint and SQL Server 2k5. My SQL

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.