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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:57:50+00:00 2026-06-03T16:57:50+00:00

I’m trying to filter a listview with arrayadapter. The arraydapter parameter is a String[][].

  • 0

I’m trying to filter a listview with arrayadapter. The arraydapter parameter is a String[][]. The problem is that anything happens. I must override the Filter interface? In that case plase, can someone provide some hints?

Every position of the array I’m trying to filter is like

 galleryValues[0][0] -> "tiulo"
              [0][1] -> "desc"
              [0][2] -> "etc"

I tryied to filter it:

lstContinente = (ListView)findViewById(R.id.list);
lstContinente.setTextFilterEnabled(true);
adapter = new PortaitArrayAdapter(cx,galleryValues);   
lstContinente.setAdapter(adapter);

ed_busqueda.addTextChangedListener(new TextWatcher() {           
    public void afterTextChanged(Editable s) {}      
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    // TODO Auto-generated method stub       
}        
public void onTextChanged(CharSequence s, int start, int before, int count) {
    adapter.getFilter().filter(s.toString());
    adapter.notifyDataSetChanged();                 
}        
});

The adapter code:

public class PortaitArrayAdapter extends ArrayAdapter<String> {
    private final Context context;
    private final String[][] values;
    private List<Imagen> imagenes = null;
    private LayoutInflater mInflater;
    public ImageLoader imageLoader;     


    public PortaitArrayAdapter(Context context, String[][] values) {
        super(context, R.layout.gallery_row);
        this.context = context;
        this.values = values;
        mInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        imagenes = new ArrayList<Imagen>();
        for (int i = 0; i < 20; i++) imagenes.add(new Imagen());
        Bitmap def = BitmapFactory.decodeResource(this.context.getResources(),R.drawable.ic_launcher);
        imageLoader=new ImageLoader(this.context,def, imagenes);
    }



    @Override
    public int getCount (){
        return this.values.length;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView =  mInflater.inflate(R.layout.gallery_row, parent, false);
            holder.txtTitulo = (TextView) convertView.findViewById(R.id.txt_gallery_titulo);
            holder.txtDesc = (TextView) convertView.findViewById(R.id.txt_gallery_desc);
            holder.txtFecha = (TextView) convertView.findViewById(R.id.txt_gallery_fecha);
            holder.txtEst = (TextView) convertView.findViewById(R.id.txt_gallery_est);
            holder.imageView    = (ImageView)convertView.findViewById(R.id.lst_img_gallery);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        /*LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.gallery_row, parent, false);*/

        //ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);


        Bitmap bmp;
        Log.v("Position --> ",String.valueOf(position));
        try {
            byte b[] = imagenes.get(position).getImageData();
            if (b != null) {
                bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
                if (bmp != null) holder.imageView.setImageBitmap(bmp);
            } else {

                String urlBase = galleryValues[position][0].substring(0, galleryValues[position][0].lastIndexOf("/")+1);
               String urlToEncode = galleryValues[position][0].substring(galleryValues[position][0].lastIndexOf("/")+1, galleryValues[position][0].length());

               urlToEncode = URLEncoder.encode(urlToEncode,"UTF-8");

               String url = urlBase.concat(urlToEncode);

               url = url.replace("+", "%20");
               Log.v("UrlFinal --> ",url);

                imageLoader.DisplayImage(String.valueOf(position),url,act,holder.imageView, position,null);
            }

        } catch (Exception e) {
            Log.e(this.getClass().getName(),"Exception en pos = " + position + " error:" + e.getMessage());
            e.printStackTrace();
        }


        holder.txtTitulo.setText(galleryValues[position][1] + ", " + galleryValues[position][2]);

        String[] dates = galleryValues[position][4].split("/");  
        String date = dates [1] + "/" + dates[0] + "/" + dates[2];
        Date d1 = new Date(date);
        DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
        holder.txtDesc.setText(galleryValues[position][3]);

        holder.txtFecha.setText(df.format(d1));
        holder.txtEst.setText(getText(R.string.num_fotos_gallery) + galleryValues[position][5] + " - " + getText(R.string.num_videos_gallery) + galleryValues[position][6] + " - " + getText(R.string.num_exp_gallery) + galleryValues[position][7]);

        return convertView;
    }

}

private static class ViewHolder {
    TextView txtTitulo;
    TextView txtDesc;
    TextView txtFecha;
    TextView txtEst;
    ImageView imageView;
}
  • 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-03T16:57:52+00:00Added an answer on June 3, 2026 at 4:57 pm

    Convert your String array to ArrayList and pass it to Adapter and use below code or change below code with your String[].

    You need to implement Filterable to your Adapter class and Override getFilter()

    Checkout this complete example for filtering custom Adapter.

    public class ListFilterActivity extends ListActivity {
    
        private List<String> list = new ArrayList<String>();
        List<String> mOriginalValues;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            final MyAdapter adapter = new MyAdapter(this, getModel());
            setListAdapter(adapter);
    
            EditText filterEditText = (EditText) findViewById(R.id.filterText);
    
            // Add Text Change Listener to EditText
            filterEditText.addTextChangedListener(new TextWatcher() {
    
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    // Call back the Adapter with current character to Filter
                    adapter.getFilter().filter(s.toString());
                }
    
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,int after) {
                }
    
                @Override
                public void afterTextChanged(Editable s) {
                }
            });
        }
    
        private List<String> getModel() {
            list.add("Linux");
            list.add("Windows7");
            list.add("Suse");
            list.add("Eclipse");
            list.add("Ubuntu");
            list.add("Solaris");
            list.add("Android");
            list.add("iPhone");
            list.add("Windows XP");
            return list;
        }
    }
    
    // Adapter Class
    public class MyAdapter extends BaseAdapter implements Filterable {
    
        List<String> arrayList;
        List<String> mOriginalValues; // Original Values
        LayoutInflater inflater;
    
        public MyAdapter(Context context, List<String> arrayList) {
            this.arrayList = arrayList;
            inflater = LayoutInflater.from(context);
        }
    
        @Override
        public int getCount() {
            return arrayList.size();
        }
    
        @Override
        public Object getItem(int position) {
            return position;
        }
    
        @Override
        public long getItemId(int position) {
            return position;
        }
    
        private class ViewHolder {
            TextView textView;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
    
            ViewHolder holder = null;
    
            if (convertView == null) {
    
                holder = new ViewHolder();
                convertView = inflater.inflate(R.layout.row, null);
                holder.textView = (TextView) convertView
                .findViewById(R.id.textview);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.textView.setText(arrayList.get(position));
            return convertView;
        }
    
        @Override
        public Filter getFilter() {
            Filter filter = new Filter() {
    
                @SuppressWarnings("unchecked")
                @Override
                protected void publishResults(CharSequence constraint,FilterResults results) {
    
                    arrayList = (List<String>) results.values; // has the filtered values
                    notifyDataSetChanged();  // notifies the data with new filtered values
                }
    
                @Override
                protected FilterResults performFiltering(CharSequence constraint) {
                    FilterResults results = new FilterResults();        // Holds the results of a filtering operation in values
                    List<String> FilteredArrList = new ArrayList<String>();
    
                    if (mOriginalValues == null) {
                        mOriginalValues = new ArrayList<String>(arrayList); // saves the original data in mOriginalValues
                    }
    
                    /********
                    *
                    *  If constraint(CharSequence that is received) is null returns the mOriginalValues(Original) values
                    *  else does the Filtering and returns FilteredArrList(Filtered)
                    *
                    ********/
                    if (constraint == null || constraint.length() == 0) {
    
                        // set the Original result to return
                        results.count = mOriginalValues.size();
                        results.values = mOriginalValues;
                    } else {
                        constraint = constraint.toString().toLowerCase();
                        for (int i = 0; i < mOriginalValues.size(); i++) {
                            String data = mOriginalValues.get(i);
                            if (data.toLowerCase().startsWith(constraint.toString())) {
                                FilteredArrList.add(data);
                            }
                        }
                        // set the Filtered result to return
                        results.count = FilteredArrList.size();
                        results.values = FilteredArrList;
                    }
                    return results;
                }
            };
            return filter;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.