Фильтр ListView с arrayadapter
Я пытаюсь отфильтровать просмотр списка с помощью arrayadapter. Параметр arraydapter является строкой [] []. Проблема в том, что все происходит. Я должен переопределить интерфейс фильтра? В таком случае, кто-то может дать некоторые советы?
Каждая позиция массива, который я пытаюсь отфильтровать, похожа на
<code> galleryValues[0][0] -> "tiulo" [0][1] -> "desc" [0][2] -> "etc" </code>
Я попытался отфильтровать это:
<code>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(); } }); </code>
Код адаптера:
<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; } </code>