Bonjour à tous,

J'ai un problème de filtre dans ma listView, quelqu'un pourrait-t-il m'aider ?

Quand j'utilise une ArrayList<ArrayList<String>>, le texte est filtré, mais l'image qui apparais n'est pas la bonne (l'ordre des images reste le même).

Quand j'utilise une ArrayList<HashMap<String,String>>, le texte n'est pas filtré correctement (tout les éléments sont filtrés dès que je tape une lettre).

Qu'est ce qui ne va pas dans mon code ? Le code ci-dessous concerne la solution avec l'ArrayList<HashMap<String, String>>)

ListActivity :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
public class myListActivity extends ListActivity{
 
    private ImageInDiscountCardListAdapter adapter;
    private EditText filterText;
    private ArrayList<HashMap<String, String>> retailerList;
    private HashMap<String, String> retailerInfo;
    private TextWatcher filterTextWatcher = new TextWatcher() {
 
        public void afterTextChanged(Editable s){
        }
 
        public void beforeTextChanged(CharSequence s, int start, int count, int after){
        }
 
        public void onTextChanged(CharSequence s, int start, int before, int count){
        	if (adapter!=null){
        		adapter.getFilter().filter(s);
        	}
        }
 
    };
 
	@Override
	public void onCreate(Bundle savedInstanceState) {
 
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_layout);
 
		addImageUrl();
 
		this.filterText = (EditText) findViewById(R.id.name);
		this.filterText.addTextChangedListener(filterTextWatcher); 	
 
		this.adapter = new ImageInDiscountCardListAdapter(this, retailerList);
		setListAdapter(adapter);
 
	}
 
	@Override
    public void onDestroy(){
 
        adapter.imageLoader.stopThread();
        setListAdapter(null);
        filterText.removeTextChangedListener(filterTextWatcher);
        super.onDestroy();
 
    }
 
    @Override
	protected void onListItemClick(ListView l, View v, int position, long id){
 
		//this.filterText.setText(this.item.get(position));
 
	}
 
	public void addImageUrl(){
 
		this.retailerList = new ArrayList<HashMap<String,String>>();
 
		this.retailerInfo = new HashMap<String, String>();
		retailerInfo.put("name", "Fnac");
		retailerInfo.put("imageUrl", "http://lesite.fr/wp-content/uploads/2010/09/FNAC.jpg");
		this.retailerList.add(retailerInfo);
 
		// etc...
 
	}
Adapter :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public class ImageInDiscountCardListAdapter extends ArrayAdapter<HashMap<String, String>> {
 
		private Activity activity;
		private ArrayList<HashMap<String, String>> retailerList;
		private static LayoutInflater inflater;
		public ImageLoader imageLoader; 
 
		public ImageInDiscountCardListAdapter(Activity activity, ArrayList<HashMap<String, String>> retailerList) {
 
			super(activity, android.R.layout.simple_list_item_1, retailerList);
			this.activity = activity;
			this.retailerList = retailerList;
			inflater = (LayoutInflater)this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			this.imageLoader = new ImageLoader(this.activity.getApplicationContext());
 
		}
 
		public static class ViewHolder{
			public TextView text;
			public ImageView image;
		}
 
		public View getView(int position, View convertView, ViewGroup parent){
 
			View view = convertView;
			ViewHolder holder;
 
			if(view == null){
				view = inflater.inflate(R.layout.retailer_row, null);
				holder = new ViewHolder();
				holder.text=(TextView)view.findViewById(R.id.retailer_name);;
				holder.image=(ImageView)view.findViewById(R.id.retailer_image);
				view.setTag(holder);
			}
 
			else{
				holder=(ViewHolder)view.getTag();
			}
 
			holder.text.setText(getItem(position).get("name"));
			holder.image.setTag(this.retailerList.get(position).get("imageUrl"));
			imageLoader.DisplayImage(this.retailerList.get(position).get("imageUrl"), activity, holder.image);
 
			return view;
 
		}
 
	}