Hi I am working on BaseAdapter , but always my last item is showing .
public View getView(int position, View convertView, ViewGroup parent){
SearchViewHolder orderViewHolder = null;
int type = getItemViewType(position);
if (convertView == null) {
orderViewHolder = new SearchViewHolder();
convertView = inflater.inflate(R.layout.order_list_row, null);
orderViewHolder.setproductname((TextView) convertView
.findViewById(R.id.orderTitle));
}
convertView.setTag(orderViewHolder);
} else {
orderViewHolder = (SearchViewHolder)convertView.getTag();
}
for (int i = 0 ; i<msearchproductname.size();i++) {
System.out.println("@@ value of productname !!!!:"+msearchproductname.get(i));
orderViewHolder.getproductname().setText(""+msearchproductname.get(i));
}
return convertView;}
Even output of
System.out.println("@@ value of productname !!!!:"+msearchproductname.get(i));
is same as we want.
What is happening wrong here. In textView it is showing always last item . Please help me.Thanks in advance to all.
ok you need to remove the loop and do it this way
public View getView(int position, View convertView, ViewGroup parent){
SearchViewHolder orderViewHolder = null;
int type = getItemViewType(position);
if (convertView == null) {
orderViewHolder = new SearchViewHolder();
convertView = inflater.inflate(R.layout.order_list_row, null);
orderViewHolder.setproductname((TextView)convertView
.findViewById(R.id.orderTitle));
convertView.setTag(orderViewHolder);
} else {
orderViewHolder = (SearchViewHolder)convertView.getTag();
}
orderViewHolder.getproductname().setText(""+msearchproductname.get(position));
return convertView;
}