如何在不使用Viewholder的情况下仅过滤自定义适配器中产品的BrandName?

时间:2015-08-26 06:18:47

标签: android listview android-listview

我正在创建一个具有自定义列表视图和自定义列表视图适配器的Android应用程序。如何在不使用viewholder的情况下使用自定义listview适配器仅过滤品牌名称?可能吗?如果是,我该如何过滤它?

Listviewadapter.java

 import java.util.ArrayList;
 import java.util.HashMap;

 import android.content.Context;
 import android.content.Intent;
 import android.graphics.Color;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
 import android.widget.ImageView;
 import android.widget.TextView;

 public class ListViewAdapter extends BaseAdapter {

 // Declare Variables
 Context context;
 LayoutInflater inflater;
 ArrayList<HashMap<String, String>> data;
 ImageLoader imageLoader;
 HashMap<String, String> resultp = new HashMap<String, String>();

 public ListViewAdapter(Context context,
                   ArrayList<HashMap<String, String>> arraylist) {
 this.context = context;
 data = arraylist;
 imageLoader = new ImageLoader(context);
 }

 @Override
 public int getCount() {
 return data.size();
 }

 @Override
public Object getItem(int position) {
return null;
}

@Override
public long getItemId(int position) {
return 0;
}

public View getView(final int position, View convertView, ViewGroup parent) {
 // Declare Variables
 TextView Brand;
 TextView Category;
 TextView Code;
 TextView Description;
 TextView Price;
 TextView Availability;
 ImageView Image;

inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View itemView = inflater.inflate(R.layout.activity_main, parent, false);
// Get the position
resultp = data.get(position);

// Locate the TextViews in listview_item.xml
Brand = (TextView) itemView.findViewById(R.id.Brand);
Category = (TextView) itemView.findViewById(R.id.Category);
Code = (TextView) itemView.findViewById(R.id.Code);
Description = (TextView) itemView.findViewById(R.id.Desscription);
Price = (TextView) itemView.findViewById(R.id.Price);

// Locate the ImageView in listview_item.xml
Image = (ImageView) itemView.findViewById(R.id.list_image);

// Capture position and set results to the TextViews
Brand.setText(resultp.get(MainActivity.Brand));
Category.setText(resultp.get(MainActivity.Category));
Code.setText(resultp.get(MainActivity.Code));
Description.setText(resultp.get(MainActivity.Description));
Price.setText(resultp.get(MainActivity.Price));
// Capture position and set results to the ImageView
// Passes flag images URL into ImageLoader.class
imageLoader.DisplayImage(resultp.get(MainActivity.Image), Image);
// Capture ListView item click

Availability = (TextView) itemView.findViewById(R.id.Availability);
if(Availability.getText().equals("Available")){

    Availability.setTextColor(Color.GREEN);

 }
 return itemView;
}



}

0 个答案:

没有答案