I would like to create ListView using CustomAdapter that extends BaseAdapter. I have CustomAdapter(Context context, List<Map<String, String>> dataList).
How do I get data from Map and set my views in the getView() method? Before I've tried to use SimpleAdapter but I need to set bitmap stored on SD, and path to image I've stored in map. Every help is appreciated.
Here's my source of CustomAdapter:
public class CustomAdapter extends BaseAdapter {
private Context context;
private String pricePrecision = null;
private List<Map<String, String>> data;
public CustomAdapter(Context context, List<Map<String, String>> data) {
super();
this.context = context;
this.data = data;
}
#Override
public int getCount() {
return (data == null) ? 0 : data.size();
}
#Override
public Object getItem(int position) {
return data.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
LayoutInflater inflater = ((LayoutInflater) context
.getSystemService(Context.LOCATION_SERVICE));
if (convertView == null) {
convertView = inflater.inflate(R.layout.order_list_item, null);
viewHolder = new ViewHolder();
viewHolder.itemThumbnail = ((ImageView) convertView
.findViewById(R.id.ivItemThumb));
viewHolder.itemName = ((TextView) convertView
.findViewById(R.id.tvItemName));
viewHolder.itemPrice = ((TextView) convertView
.findViewById(R.id.tvItemPrice));
convertView.setTag(viewHolder);
} else {
viewHolder = ((ViewHolder) convertView.getTag());
}
return null;
}
private class ViewHolder {
private ImageView itemThumbnail;
private TextView itemName;
private TextView itemPrice;
}
}
Change your getView method as :
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
LayoutInflater inflater = ((LayoutInflater) context
.getSystemService(Context.LOCATION_SERVICE));
if (convertView == null) {
convertView = inflater.inflate(R.layout.order_list_item, null);
viewHolder = new ViewHolder();
viewHolder.itemThumbnail = ((ImageView) convertView
.findViewById(R.id.ivItemThumb));
viewHolder.itemName = ((TextView) convertView
.findViewById(R.id.tvItemName));
viewHolder.itemPrice = ((TextView) convertView
.findViewById(R.id.tvItemPrice));
convertView.setTag(viewHolder);
} else {
viewHolder = ((ViewHolder) convertView.getTag());
}
viewHolder.itemThumbnail.setImageBitmap(data.get(position).get("thumbnail"));
viewHolder.itemName.setText(data.get(position).get("name"));
viewHolder.itemPrice.setText(""+data.get(position).get("price"));
return viewHolder;
}
private class ViewHolder {
private ImageView itemThumbnail;
private TextView itemName;
private TextView itemPrice;
}
A little addition to (ρяσѕρєя K)'s code.
You might want to set listeners on your thumbnails.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
LayoutInflater inflater = ((LayoutInflater) context
.getSystemService(Context.LOCATION_SERVICE));
if (convertView == null) {
convertView = inflater.inflate(R.layout.order_list_item, null);
viewHolder = new ViewHolder();
viewHolder.itemThumbnail = ((ImageView) convertView
.findViewById(R.id.ivItemThumb));
viewHolder.itemName = ((TextView) convertView
.findViewById(R.id.tvItemName));
viewHolder.itemPrice = ((TextView) convertView
.findViewById(R.id.tvItemPrice));
viewHolder.itemThumbnail.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
convertView.setTag(viewHolder);
} else {
viewHolder = ((ViewHolder) convertView.getTag());
}
viewHolder.itemThumbnail.setImageBitmap(data.get(position).get(
"thumbnail"));
viewHolder.itemName.setText(data.get(position).get("name"));
viewHolder.itemPrice.setText("" + data.get(position).get("price"));
return viewHolder;
}
private class ViewHolder {
private ImageView itemThumbnail;
private TextView itemName;
private TextView itemPrice;
}
Related
Here is class which i load the images locally from drawable i want to shows the actual images not double images in list.
public class ActivityIntroduction extends Activity {
ListView list;
Integer[] imgid={
R.drawable.introduction_1,R.drawable.introduction_2,R.drawable.introduction_3,
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
// findViewById(R.id.title1).setBackgroundResource(R.drawable.duwaine_head);
findViewById(R.id.btn_back1).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
ActivityIntroduction.this.finish();
}
});
AdapterListextends adapter=new AdapterListextends(this, imgid);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
}
}
Here is Adapter but when i scroll the list speedily then the images shows double or repeatly
class AdapterListextends extends ArrayAdapter<Integer> {
LayoutInflater vi;
private final Activity context;
private final Integer[] imgid;
ViewHolder holder;
public AdapterListextends(Activity context, Integer[] imgid) {
super(context, R.layout.row_view, imgid);
vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.context = context;
this.imgid = imgid;
}
static class ViewHolder {
protected static ImageView imageview;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
holder = new ViewHolder();
v = vi.inflate(R.layout.row_view, null);
holder.imageview = (ImageView) v.findViewById(R.id.ivImage);
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
holder.imageview.setImageResource(imgid[position]);
return v;
}
}
Olny change the Holder static to final
change ViewHolder imageview acess from protected static to private
static class ViewHolder {
private ImageView imageview;
}
it should work
Yes but i make this View Holder and it work fine for me
class AdapterListextends extends ArrayAdapter<Integer> {
LayoutInflater vi;
private final Activity context;
private final Integer[] imgid;
public AdapterListextends(Activity context, Integer[] imgid) {
super(context, R.layout.row_view, imgid);
vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.context = context;
this.imgid = imgid;
}
final class ViewHolder {
ImageView imageview;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.row_view, null);
final ViewHolder viewHolder = new ViewHolder();
view.setTag(viewHolder);
viewHolder.imageview = (ImageView) view.findViewById(R.id.ivImage);
// viewHolder.type = (TextView) view.findViewById(R.id.Type);
} else {
view = convertView;
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.imageview.setImageResource(imgid[position]);
return view;
}
}
It might be silly question, but I am having bit hard time to make it work.
I have a custom list view adapter which some textview and imageview.
But when I am updating listview using custom adapter it is only updating last value. here is my code
Adapter code
public class InfoListAdapter extends ArrayAdapter<aSProperty> {
Context mContext;
List<aSProperty> values= null;
public InfoListAdapter(Context mContext, List<aSProperty> data) {
super(mContext, R.layout.list_row, data);
this.mContext = mContext;
this.values = data.;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_row, null);
signal = (ImageView) convertView.findViewById(R.id.images);
type = (TextView) convertView.findViewById(R.id.type);
info = (TextView) convertView.findViewById(R.id.info);
image.setBackgroundResource(R.drawable.abc);
Log.d(TAG, "List Size"+values.size());
for(int i = 0; i < values.size(); i++){
Log.d(TAG, "DATA"+values.get(i).type);
type.setText(values.get(i).type);
}
}
ImageView image;
TextView type;
TextView info;
static String TAG= "InfoListAdapter";
return convertView;
}
}
Code to populate adapter
info_panel = new InfoListAdapter(esActivity.this, allData);
list.setAdapter(info_panel);
But I do not know why, it is only showing last values from values list. In addition I want to change image based on condition and data inside values, any good way to do this.
use following code
public class InfoListAdapter extends ArrayAdapter<aSProperty> {
Context mContext;
List<aSProperty> values= null;
public InfoListAdapter(Context mContext, List<aSProperty> data) {
super(mContext, R.layout.list_row, data);
this.mContext = mContext;
this.values = data.;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_row, null);
signal = (ImageView) convertView.findViewById(R.id.images);
type = (TextView) convertView.findViewById(R.id.type);
info = (TextView) convertView.findViewById(R.id.info);
image.setBackgroundResource(R.drawable.abc);
Log.d(TAG, "List Size"+values.size());
type.setText(values.get(position).type);
}
ImageView image;
TextView type;
TextView info;
static String TAG= "InfoListAdapter";
return convertView;
}
}
First of all, you have to override getCount() method of your adapter like this
#Override
public int getCount() {
return values .size();
}
and then in your getView() method you have to do something like this
#Override
public View getView(int arg0, View convertView, ViewGroup arg2) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = layoutInflater.inflate(R.layout.mycartslistcontents,
null);
holder.yourImageView= (ImageView) convertView
.findViewById(R.id.image);
holder.yourTextView= (TextView) convertView
.findViewById(R.id.textview);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
// here set your textView text and image resource
return convertView;
}
Don't forget to take a global variable layoutInflater at the top like this
private LayoutInflater layoutInflater;
and initialise it in your constructor this way
layoutInflater = LayoutInflater.from(yourContext);
and here is your ViewHolder class
static class ViewHolder {
ImageView yourImageView;
TextView yourTextView;
}
here is my Adapter:
public class MainAdapter extends BaseAdapter implements View.OnClickListener {
private Context context;
private LayoutInflater inflater;
private Map<Integer, Info[]> originalDatas;
public MainAdapter(Context context, Map<Integer, Info[]> infoList) {
this.context = context;
originalDatas = infoList;
inflater = LayoutInflater.from(context);
}
#Override
public int getCount() {
return originalDatas.size();
}
#Override
public Object getItem(int position) {
return originalDatas.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = inflater.inflate(R.layout.grid_list_row, null);
final ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
viewHolder.rightText = (TextView) convertView.findViewById(R.id.rightText);
viewHolder.leftText = (TextView) convertView.findViewById(R.id.leftText);
viewHolder.centerText = (TextView) convertView.findViewById(R.id.centerText);
viewHolder.rightText.setTypeface(TypeFaces.getTypeFace(context, TypeFaces.FONT_REGULAR));
viewHolder.leftText.setTypeface(TypeFaces.getTypeFace(context, TypeFaces.FONT_REGULAR));
viewHolder.centerText.setTypeface(TypeFaces.getTypeFace(context, TypeFaces.FONT_REGULAR));
viewHolder.rightText.setOnClickListener(this);
viewHolder.centerText.setOnClickListener(this);
viewHolder.leftText.setOnClickListener(this);
convertView.setTag(viewHolder);
} else viewHolder = (ViewHolder) convertView.getTag();
Iterator<Integer> iterator = originalDatas.keySet().iterator();
while (iterator.hasNext()) {
Info[] infos = originalDatas.get(iterator.next());
viewHolder.rightText.setText(infos[0].getTitle());
viewHolder.centerText.setText(infos[1].getTitle());
if (infos[2] != null)
viewHolder.leftText.setText(infos[2].getTitle());
else
viewHolder.leftText.setVisibility(View.INVISIBLE);
}
return convertView;
}
#Override
public void onClick(View v) {
String titleText = ((TextView) v).getText().toString();
if (titleText != "") {
Intent intent = new Intent(context, SecondActivity.class);
intent.putExtra("parent", titleText);
Toast.makeText(context, titleText, Toast.LENGTH_SHORT).show();
context.startActivity(intent);
}
}
static class ViewHolder {
TextView rightText;
TextView centerText;
TextView leftText;
}
}
it gives me a nullpioterexception on
viewHolder.rightText.setText(infos[0].getTitle());
why is the problem?
i also used this :
while (iterator.hasNext() && viewHolder!=null) {
Info[] infos = originalDatas.get(iterator.next());
viewHolder.rightText.setText(infos[0].getTitle());
viewHolder.centerText.setText(infos[1].getTitle());
if (infos[2] != null)
viewHolder.leftText.setText(infos[2].getTitle());
else
viewHolder.leftText.setVisibility(View.INVISIBLE);
}
but all rows fills by first row data , and when i select textviews it does not work
convertView = inflater.inflate(R.layout.grid_list_row, null);
final ViewHolder viewHolder;
if (convertView == null) {
convertView is never null in your code, and ViewHolder is never initialized. Change it like
final ViewHolder viewHolder
if (convertView == null) {
convertView = inflater.inflate(R.layout.grid_list_row, null);
I have a problem with my custom adapter. the method getView() is not called. I searched on my friends "google" and "stackoverflow" but anything fix my problem.
public class custom_adapter extends BaseAdapter {
private List<Activities> listData;
private LayoutInflater layoutInflater;
public custom_adapter(Context context,
List<Activities> listActivity) {
this.listData = listActivity;
layoutInflater = layoutInflater.from(context);
Log.v("BaseAdapter", "custom_adapter");
}
#Override
public int getCount() {
Log.v("BaseAdapter - getCount", String.valueOf(listData.size()));
return listData.size();
}
#Override
public Object getItem(int position) {
return listData.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.v("BaseAdapter", "getView");
ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.custom_adapter, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.title);
holder.ratingBar = (RatingBar) convertView.findViewById(R.id.averageRatingBarActivitySearch);
holder.imageView = (ImageView) convertView.findViewById(R.id.thumbImage);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Activities newsItem = (Activities) listData.get(position);
holder.name.setText(newsItem.getName());
holder.ratingBar.setRating(newsItem.getAverageMark());
if (holder.imageView != null) {
new ImageDownloaderTask(holder.imageView).execute(newsItem.getPictureActivityString());
}
return convertView;
}
public static class ViewHolder {
TextView name;
RatingBar ratingBar;
ImageView imageView;
}
}
Furthermore, GetCount is not null !
I will be very glade if you can help me
Regards
K.L
For the purpose of handling List of some objects, extending generic ArrayAdapter may be better choice instead of just BaseAdapter. It will handle a lot of things for you. Your whole adapter class could look like.
public class ActivitiesAdapter extends ArrayAdapter<Activities>
{
private LayoutInflater layoutInflater;
public ActivitiesAdapter(Context context, List<Activities> objects)
{
super(context, 0, objects);
layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.v("BaseAdapter", "getView");
ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.custom_adapter, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.title);
holder.ratingBar = (RatingBar) convertView.findViewById(R.id.averageRatingBarActivitySearch);
holder.imageView = (ImageView) convertView.findViewById(R.id.thumbImage);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Activities newsItem = getItem(position);
holder.name.setText(newsItem.getName());
holder.ratingBar.setRating(newsItem.getAverageMark());
if (holder.imageView != null) {
new ImageDownloaderTask(holder.imageView).execute(newsItem.getPictureActivityString());
}
return convertView;
}
public static class ViewHolder {
TextView name;
RatingBar ratingBar;
ImageView imageView;
}
}
and of course you have to set this adapter to your ListView instance. Like
ActivitiesAdapter adapter = new ActivitiesAdapter(this, yourActivitiesList);
ListView listView = (ListView)findViewById(R.id.my_list_id);
listView.setAdapter(adapter);
or simply setListAdapter(adapter); if you are using ListActivity or ListFragment;
I had the same problem. Maybe, the problem is that you don't notify your adapter that you've changed data in the adapter. Try this code in your adapter:
#Override
public int getCount() {
return data.size();
}
And call notifyDataSetChanged(); when you change the data in Adapter.
I am creating a custom list view using baseadapter.i have 10 list item in my list.my problem is that afetr 6 items ,the first 4 are repeating.i just printed position values in getview.it gives 0,1,2,3,4,5,6,7,8,9,0,1,2,3.My code is below.
thanx in advance
public class ProductListAdapter extends BaseAdapter implements OnClickListener{
/*
* developer :sanu
* date :10-4-2013
* time :3.34 pm
*/
public View row;
private String[] productName;
private String[] producttype;
private String[] priceRangeFrom;
private String[] priceRangeTo;
private String[] productImage;
private Activity activity;
private static LayoutInflater inflater=null;
static String posClicked;
ViewHolder holder;
Integer height1;
Integer width1;
Typeface tf;
Integer FirmaCount;
public ImageLoader imageLoader;
public ProductListAdapter(Activity a,String[] name,String[] type,String[] price_from,String[] price_to,String[] image,Typeface tf) {
activity = a;
productName = name;
producttype = type;
priceRangeFrom = price_from;
priceRangeTo = price_to;
productImage = image;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return productName.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public int getViewTypeCount (int position)
{
return position;
}
public static class ViewHolder{
public TextView nameProduct;
public TextView typeProduct;
public TextView priceRangeProduct;
public ImageView productImage;
public ImageView plusImage;
public RelativeLayout mainLayout;
public int position;
}
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = inflater.inflate(R.layout.product_list_details,parent, false);
holder=new ViewHolder();
holder.nameProduct =(TextView)convertView.findViewById(R.id.name);
holder.typeProduct =(TextView)convertView.findViewById(R.id.product);
holder.priceRangeProduct =(TextView)convertView.findViewById(R.id.pricerange);
holder.productImage =(ImageView)convertView.findViewById(R.id.image);
holder.plusImage =(ImageView)convertView.findViewById(R.id.dot);
holder.mainLayout = (RelativeLayout)convertView.findViewById(R.id.mainlayout);
holder.nameProduct.setText(productName[position]);
if(producttype[position].length()>18)
{
holder.typeProduct.setText(producttype[position].substring(0,18)+"...");
}
else
{
holder.typeProduct.setText(producttype[position]);
}
holder.priceRangeProduct.setText(priceRangeFrom[position].substring(0,priceRangeFrom[position].length()-2)+" To "+priceRangeTo[position].substring(0, priceRangeTo[position].length()-2));
imageLoader.DisplayImage(productImage[position], holder.productImage);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder)convertView.getTag();
}
holder.plusImage.setTag(Integer.toString(position));
holder.plusImage.setOnClickListener(this);
holder.mainLayout.setTag(Integer.toString(position));
holder.mainLayout.setOnClickListener(this);
return convertView;
}
This sounds like a case of View re-cyclcing. Android will pass a pre-populated view to the getView method. It does so to minimize object creation. When an existing row-view is scrolled off screen, Android might try to recycle that view to display a row that is now on-screen. You need to account for the fact that this view may have been used to display data for another row (which is now off screen).
You have the following line
holder.typeProduct.setText
within the following conditional:
if(convertView == null){
Move that line outside of the conditional, and all should be well.
It's like EJK said. You are not recycling your view correctly. Change your code to this and notice where I put the setText calls
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = inflater.inflate(R.layout.product_list_details,parent, false);
holder=new ViewHolder();
holder.nameProduct =(TextView)convertView.findViewById(R.id.name);
holder.typeProduct =(TextView)convertView.findViewById(R.id.product);
holder.priceRangeProduct =(TextView)convertView.findViewById(R.id.pricerange);
holder.productImage =(ImageView)convertView.findViewById(R.id.image);
holder.plusImage =(ImageView)convertView.findViewById(R.id.dot);
holder.mainLayout = (RelativeLayout)convertView.findViewById(R.id.mainlayout);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder)convertView.getTag();
}
holder.plusImage.setTag(Integer.toString(position));
holder.plusImage.setOnClickListener(this);
holder.mainLayout.setTag(Integer.toString(position));
holder.mainLayout.setOnClickListener(this);
//setText functions are here
holder.nameProduct.setText(productName[position]);
if(producttype[position].length()>18)
{
holder.typeProduct.setText(producttype[position].substring(0,18)+"...");
}
else
{
holder.typeProduct.setText(producttype[position]);
}
holder.priceRangeProduct.setText(priceRangeFrom[position].substring(0,priceRangeFrom[position].length()-2)+" To "+priceRangeTo[position].substring(0, priceRangeTo[position].length()-2));
imageLoader.DisplayImage(productImage[position], holder.productImage);
return convertView;
}
Change your getView to
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = inflater.inflate(R.layout.product_list_details,parent, false);
holder=new ViewHolder();
holder.nameProduct =(TextView)convertView.findViewById(R.id.name);
holder.typeProduct =(TextView)convertView.findViewById(R.id.product);
holder.priceRangeProduct =(TextView)convertView.findViewById(R.id.pricerange);
holder.productImage =(ImageView)convertView.findViewById(R.id.image);
holder.plusImage =(ImageView)convertView.findViewById(R.id.dot);
holder.mainLayout = (RelativeLayout)convertView.findViewById(R.id.mainlayout);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.nameProduct.setText(productName[position]);
if(producttype[position].length()>18)
{
holder.typeProduct.setText(producttype[position].substring(0,18)+"...");
}
else
{
holder.typeProduct.setText(producttype[position]);
}
holder.priceRangeProduct.setText(priceRangeFrom[position].substring(0,priceRangeFrom[position].length()-2)+" To "+priceRangeTo[position].substring(0, priceRangeTo[position].length()-2));
imageLoader.DisplayImage(productImage[position], holder.productImage);
holder.plusImage.setTag(Integer.toString(position));
holder.plusImage.setOnClickListener(this);
holder.mainLayout.setTag(Integer.toString(position));
holder.mainLayout.setOnClickListener(this);
return convertView;
}
Also check this
How ListView's recycling mechanism works
Change getView()
Declare ViewHolder before if (convertView == null)
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.product_list_details,
parent, false);
holder = new ViewHolder();
holder.nameProduct = (TextView) convertView.findViewById(R.id.name);
holder.typeProduct = (TextView) convertView
.findViewById(R.id.product);
holder.priceRangeProduct = (TextView) convertView
.findViewById(R.id.pricerange);
holder.productImage = (ImageView) convertView
.findViewById(R.id.image);
holder.plusImage = (ImageView) convertView.findViewById(R.id.dot);
holder.mainLayout = (RelativeLayout) convertView
.findViewById(R.id.mainlayout);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.nameProduct.setText(productName[position]);
if (producttype[position].length() > 18) {
holder.typeProduct.setText(producttype[position].substring(0, 18)
+ "...");
} else {
holder.typeProduct.setText(producttype[position]);
}
holder.priceRangeProduct.setText(priceRangeFrom[position].substring(0,
priceRangeFrom[position].length() - 2)
+ " To "
+ priceRangeTo[position].substring(0,
priceRangeTo[position].length() - 2));
imageLoader.DisplayImage(productImage[position], holder.productImage);
holder.plusImage.setTag(Integer.toString(position));
holder.plusImage.setOnClickListener(this);
holder.mainLayout.setTag(Integer.toString(position));
holder.mainLayout.setOnClickListener(this);
return convertView;
}