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

  • Home
  • SEARCH
  • 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 6223637
In Process

The Archive Base Latest Questions

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

I have been struggling with this for a while and can’t find the answer

  • 0

I have been struggling with this for a while and can’t find the answer despite looking for a while. I have a custom arrayAdapter which populates my list view with a custom object POI.

package com.WasserSportLotse;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.ImageView;
import android.widget.TextView;

class poiAdapter extends ArrayAdapter<POI>{


    private ArrayList<POI> items;
    private Context mContext;
    public ArrayList<POI> allItems;
    private Filter filter;
    public ArrayList<POI> filtered;

    public poiAdapter(Context context, int textViewResourceId, ArrayList<POI> items){
        super(context, textViewResourceId, items);
        mContext = context;
        this.items = items;


}

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.list_items, null);
            }
            POI poi = items.get(position);
            if (poi != null) {
                    TextView mDistanceTextView = (TextView) v.findViewById(R.id.listitems_distancetxt);
                    TextView mNameTextView = (TextView) v.findViewById(R.id.listitems_nametxt);
                    TextView mCategoryTextView = (TextView) v.findViewById(R.id.listitems_categorytxt);
                    if (mDistanceTextView != null) {
                        mDistanceTextView.setText(poi.getDistance()+"km");                            
                        }
                    if(mNameTextView != null){
                        mNameTextView.setText(poi.getName());
                    }
                    if(mCategoryTextView != null){
                        mCategoryTextView.setText(poi.getType());
                        setImage(poi.getType(), v);

                    }
            }
            return v;
    }

    private void setImage(String type, View v) {
        if ("shopping".equals(type)){
            ImageView mImage = (ImageView) v.findViewById(R.id.imageView1);
            mImage.setImageResource(R.drawable.shopping);
        }
        if ("liegestelle".equals(type)){
            ImageView mImage = (ImageView) v.findViewById(R.id.imageView1);
            mImage.setImageResource(R.drawable.liegestelle);
        }
        if ("restaurant".equals(type)){
            ImageView mImage = (ImageView) v.findViewById(R.id.imageView1);
            mImage.setImageResource(R.drawable.restaurant);
        }
        if ("schleuse".equals(type)){
            ImageView mImage = (ImageView) v.findViewById(R.id.imageView1);
            mImage.setImageResource(R.drawable.schleuse);
        }
        if ("verein".equals(type)){
            ImageView mImage = (ImageView) v.findViewById(R.id.imageView1);
            mImage.setImageResource(R.drawable.verein);
        }
        if ("tankstelle".equals(type)){
            ImageView mImage = (ImageView) v.findViewById(R.id.imageView1);
            mImage.setImageResource(R.drawable.tankstelle);
        }
        if ("faekalien".equals(type)){
            ImageView mImage = (ImageView) v.findViewById(R.id.imageView1);
            mImage.setImageResource(R.drawable.faekalien);
        }
        if ("werkstatt".equals(type)){
            ImageView mImage = (ImageView) v.findViewById(R.id.imageView1);
            mImage.setImageResource(R.drawable.werkstatt);
        }
        if ("uebernachtung".equals(type)){
            ImageView mImage = (ImageView) v.findViewById(R.id.imageView1);
            mImage.setImageResource(R.drawable.uebernachtung);
        }

    }



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

    private class POITypeFilter extends Filter
    {

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            // NOTE: this function is *always* called from a background thread, and
            // not the UI thread.
            constraint = constraint.toString().toLowerCase();
            FilterResults result = new FilterResults();
            if(constraint != null && constraint.toString().length() > 0)
            {
                ArrayList<POI> filt = new ArrayList<POI>();
                ArrayList<POI> lItems = new ArrayList<POI>();
                synchronized (this)
                {
                    lItems.addAll(items);
                }
                for(int i = 0, l = lItems.size(); i < l; i++)
                {
                    POI m = lItems.get(i);
                    if(m.getType().toLowerCase().contains(constraint))
                        filt.add(m);
                }
                result.count = filt.size();
                result.values = filt;
            }
            else
            {
                synchronized(this)
                {
                    result.values = items;
                    result.count = items.size();
                }
            }
            return result;
        }

        @SuppressWarnings("unchecked")
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            // NOTE: this function is *always* called from the UI thread.
            filtered = (ArrayList<POI>)results.values;
            notifyDataSetChanged();
            clear();
            for(int i = 0, l = filtered.size(); i < l; i++)
                add(filtered.get(i));
            notifyDataSetInvalidated();
        }

    }


}

I am trying to Override the getFilter method so I can filter each POI by POI.type and update the listView. I am calling the getFilter like so

    @Override
protected void onRestart() {
    super.onRestart();
    mAdapter.getFilter().filter(getFilterSettings());
    mAdapter.notifyDataSetChanged();
}

This just returns a black screen as if everything has been filtered out. I put breakpoints in over the getFilter but the app does enter into it so I am not sure the app is using this code. Is there something obvious that I am missing?

UPDATE – Half way there

I had a couple of problems here. It looked as tho the app wasn’t calling getFilter as the breakpoints where not stopping there. In fact the Davlik Virtual Machine can only use so many break points (it’s not so many to keep it in mind). It stopped using the breakpoints at exactly the time I use the code I wanted to analyse. I think I was pretty unlucky.

Then where where some problems with the code.I changed

 private ArrayList<POI> items; 

to public. So it could be read into a new array and that filters the results. Now just to figure out how to make the arrayAdapter to filter again but on the original array. Wow this is turning out to be a long process.

  • 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-24T08:31:30+00:00Added an answer on May 24, 2026 at 8:31 am

    if you want to make a custom filter, all you have to do is create a toString() method on your POI class that returns the value you want to filter by.

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

Sidebar

Related Questions

I have been struggling with this seeminly easy problem for 48 hours, and I
I've been struggling for this for a while now. I'm trying to gear up
I've been struggling with this for a little while now.. I am using this
I've been struggling with this problem, and while something elegant would be preferred any
This may seem like a very simple question, but I have been struggling with
I have been struggling with this for the past hour and I was wondering
I have been struggling with this jQuery Validation Plugin. Here is the code: <script
I have been struggling with this all day and have tried going through the
I have been struggling with the best way to make sure that the certain
I have for the last several years been struggling to understand why the Internet

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.