В моем приложении я создал собственное представление списка, и я хочу реализовать фильтр, чтобы список можно было фильтровать в соответствии с текстом, введенным в EditText. Я использую BaseAdapter как отдельный класс.listview custom from json getfilter
это мой адаптер:
общественного класса MyAdapter расширяет BaseAdapter {
// Declare Variables
Context context;
LayoutInflater inflater;
ArrayList<HashMap<String, String>> data;
ImageLoader imageLoader;
public HashMap<String, String> resultp;
public AllProductAdapter(Context context,
ArrayList<HashMap<String, String>> arraylist) {
this.context = context;
data = arraylist;
imageLoader = new ImageLoader(context);
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// Declare Variables
TextView namaBarang;
ImageView image;
TextView harga;
ImageButton cart;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.listview_viewitem, parent,
false);
// Get the position from the results
resultp = new HashMap<String, String>();
resultp = data.get(position);
// Locate the TextViews in listview_item.xml
namaBarang = (TextView) itemView.findViewById(R.id.judul);
cart = (ImageButton) itemView.findViewById(R.id.cart);
harga = (TextView) itemView.findViewById(R.id.posterFile);
image = (ImageView) itemView.findViewById(R.id.poster);
// Capture position and set results to the TextViews
namaBarang.setText(resultp.get(AllProductAgent.TITLE));
harga.setText(resultp.get(AllProductAgent.HARGA),
TextView.BufferType.SPANNABLE);
Spannable spannable = (Spannable) harga.getText();
spannable.setSpan(new StrikethroughSpan(), 0,
resultp.get(AllProductAgent.HARGA).length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// Capture position and set results to the ImageView
// Passes flag images URL into ImageLoader.class to download and cache
// images
imageLoader
.DisplayImageList(resultp.get(AllProductAgent.GAMBAR), image);
// Link to Register Screen
itemView.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
// Add ArrayList
cart.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Get the position from the results
HashMap<String, String> resultp = new HashMap<String, String>();
resultp = data.get(position);
// show toast if item was been added to cart
Toast.makeText(
context,
resultp.get(AllProductAgent.TITLE)
+ " has been added to Cart", Toast.LENGTH_LONG)
.show();
HashMap<String, String> map = new HashMap<String, String>();
map.put("nama", resultp.get(AllProductAgent.TITLE));
map.put("harga", resultp.get(AllProductAgent.HARGA));
map.put("link_gambar", resultp.get(AllProductAgent.GAMBAR));
map.put("website", resultp.get(AllProductAgent.WEBSITE));
BaseActivity.cartList.add(map);
}
});
itemView.setBackgroundColor(position % 2 == 0 ? Color
.parseColor("#c7eaf8") : Color.parseColor("#FFFFFF"));
return itemView;
}
как я могу фильтруется свои приложения? Я пытаюсь так много кода и до сих пор не могу его получить.
благодаря
ваш список адаптер должен реализовать интерфейс Фильтруемые – pskink
я знаю, что, но я уже стараюсь много и я все еще не в состоянии фильтровать мой адаптер. ты знаешь как? спасибо – zacky
уверен, см. мой ответ здесь: http://stackoverflow.com/questions/19858843/how-to-dynamically-add-suggestions-to-autocompletetextview-with-preserving-chara – pskink