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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:49:16+00:00 2026-06-16T11:49:16+00:00

I am a begginer in Android but I tried to make a custom listview

  • 0

I am a begginer in Android but I tried to make a custom listview filtering and I it worked somehow. The only problem I have is that the ArrayList that I am having image view and when I search for list it works but images are displayed wrong. I can’t explain this but I thought that you can help me somehow.

Anyway here is the Custom ArrayAdaptor :

public class Listadapter extends ArrayAdapter<HashMap<String, String>> {
    ArrayList<HashMap<String, String>> originalList;
    ArrayList<HashMap<String, String>> productlist;
    private ProductFilter filter;

    public Listadapter(Context context, int textViewResourceId,
            ArrayList<HashMap<String, String>> Strings) {
        super(context, textViewResourceId, Strings);
        this.productlist = new ArrayList<HashMap<String, String>>();
        this.productlist.addAll(productList);
        this.originalList = new ArrayList<HashMap<String, String>>();
        this.originalList.addAll(productList);
    }

    @Override
    public Filter getFilter() {
        if (filter == null) {
            filter = new ProductFilter();
        }
        return filter;
    }

    /*private class ViewHolder {
            TextView txtprodName;
            TextView txtcategory;
            TextView txtOfferDate;
            ImageView ProductImage;
        }*/

    public int getCount() {
        return productList.size();
    }

    public long getItemId(int position) {
        // return productList.indexOf(getItem(position));
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //ViewHolder holder = null;
        TextView txtprodName, txtcategory, txtOfferDate;
        ImageView ProductImage;
        Log.v("ConvertView", String.valueOf(position));
        //if (convertView == null) {

        LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate(R.layout.product_list_item, null);

        //holder = new ViewHolder();
        txtprodName = (TextView) convertView
                .findViewById(R.id.txtprodName);
        txtcategory = (TextView) convertView
                .findViewById(R.id.txtcategory);
        txtOfferDate = (TextView) convertView
                .findViewById(R.id.txtOfferDate);
        ProductImage = (ImageView) convertView
                .findViewById(R.id.ProductImage);
        //convertView.setTag(holder);

        /*} else {
                //holder = (ViewHolder) convertView.getTag();
            }*/
        HashMap<String, String> hm = productList.get(position);

        // txtUserName.setText(lstUsers.get(position).getFirst_Name()+" "+lstUsers.get(position).getLast_Name());
        txtprodName.setText(hm.get(TAG_PRODUCT_NAME));
        txtcategory.setText(hm.get(TAG_CATEGORY_NAME));
        txtOfferDate.setText(hm.get(TAG_OFFER_START_TIME));

        if (drawable.get(position) != null)
            ProductImage.setImageDrawable(drawable.get(position));
        else
            ProductImage.setImageResource(R.drawable.nopic_place);
    }
    return convertView;
}

private class ProductFilter extends Filter {
    @Override
    protected FilterResults performFiltering(CharSequence constraint) {
        constraint = constraint.toString().toLowerCase();
        FilterResults result = new FilterResults();
        if (constraint != null && constraint.toString().length() > 0) {
            ArrayList<HashMap<String, String>> filteredItems = 
                    new ArrayList<HashMap<String, String>>();
            for (int i = 0, l = originalList.size(); i < l; i++) {
                // ArrayList<HashMap<String, String>> p =
                // originalList.get(i);
                HashMap<String, String> p = originalList.get(i);
                if (p.toString().toLowerCase().contains(constraint))
                    filteredItems.add(p);
            }
            result.count = filteredItems.size();
            result.values = filteredItems;
        } 
        else {
            synchronized (this) {
                result.values = originalList;
                result.count = originalList.size();
            }
        }
        return result;
    }

    @SuppressWarnings("unchecked")
    @Override
    protected void publishResults(CharSequence constraint,
            FilterResults results) {
        // TODO Auto-generated method stub
        productList = (ArrayList<HashMap<String, String>>) results.values;
        notifyDataSetChanged();
        clear();
        for (int i = 0, l = productList.size(); i < l; i++)
            add(productList.get(i));
        notifyDataSetInvalidated();
    }
}

following is the result

enter image description here
enter image description here

  • 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-06-16T11:49:17+00:00Added an answer on June 16, 2026 at 11:49 am

    You can have a look at this reference.

    This is solved and working thing same as per your requirement.

    Search Filtering List View

    Go through with this link and let me know if you have still issues.

    EDIT:

    You have to maintain one dummy_drawable ArrayList same as drawable ArrayList and just keep your drawable ArrayList as base only and use dummy_drawable in your adapter.

    Also update this dummy_drawable ArrayList from your FilterResults method. Like this:

    dummy_drawable.clear();
    
    for (int i = 0, l = originalList.size(); i < l; i++) {
            // ArrayList<HashMap<String, String>> p =
            // originalList.get(i);
            HashMap<String, String> p = originalList.get(i);
            if (p.toString().toLowerCase().contains(constraint)){
                  filteredItems.add(p);
                  dummy_drawable.add(drawable.get(i));                 
            }
    }
    

    Thanks.

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

Sidebar

Related Questions

i am begginer to jquery and have a simple problem.. I want to make
I am a begginer in android,here I have activity that use web service: SoapObject
I beginer programmer,and don't have any QA experience (only simple test that i write
I am absolute begginer in android devlopment and i want to make a camera
I started using zombiejs, but i have some begginer questions: 1.) How testing ajax
I have spent a lot of time to resolve this problem. I'm begginer in
I am a begginer in android. I have a simple code, where I am
I`m quite begginer at WPF. I have checkBox and I want that every check
Begginer to Android development. I am developing a application, which have three different tabs.
I'am begginer in android programming and I'am trying to create app that is logging

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.