I am newbie to Android, I am working on a ListView
with customlistitems containing Images and some text, I found a problem when i am scrolling up/down the listview the positions of listItems are changing. So can any one help me in this please? I am posting my adapter here for your information. Hope you will help me to figure it out.
OfferAdapter
public class OfferAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<Offer> OfferList;
public OfferAdapter(Context c, ArrayList<Offer> OfferList) {
mContext = c;
this.OfferList = OfferList;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return OfferList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid;
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
grid = new View(mContext);
grid = inflater.inflate(R.layout.raw_offer, null);
TextView tv_ofr_hdr = (TextView) grid.findViewById(R.id.tv_ofr_hdr);
ImageView iv_pic = (ImageView) grid.findViewById(R.id.iv_pic);
TextView tv_ofr_desc = (TextView) grid.findViewById(R.id.tv_ofr_desc);
TextView tv_date = (TextView) grid.findViewById(R.id.tv_date);
tv_ofr_desc.setText(OfferList.get(position).getDescription());
tv_ofr_hdr.setText(OfferList.get(position).getHeadline());
Date from = new Date();
Date to = new Date();
SimpleDateFormat input = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat output = new SimpleDateFormat("dd/MM/yyyy");
try {
from = input.parse(OfferList.get(position).getStart_date());
to = input.parse(OfferList.get(position).getEnd_date()); // parse input
} catch (ParseException e) {
e.printStackTrace();
}
tv_date.setText(output.format(from) + " TO " + output.format(to));
Picasso.with(mContext)
.load(OfferList.get(position).getPhoto().replaceAll(" ", "%20"))
.placeholder(R.drawable.ic_no_img)
.error(R.drawable.ic_no_img)
.into(iv_pic);
} else {
grid = (View) convertView;
}
return grid;
}
}