I have fetching 13 item from database and try to set it to the custom listview using ArrayAdepter, but problem is that whenever I scroll to bottom, position order is 0,1,2,3,4,5,6,7,8,9,10,11,12, but if I scroll from bottom to top its giving wrong position like 6,5,4,3,2,1,0,12,11,...
always getting wrong position from bottom scroll.
I have already read and implemented all the solution on stackoverflow, but not solve it.
Here is my arrayadepter code
public class ListAdapter_home extends ArrayAdapter {
List list = new ArrayList();
Context contect;
SharedPreferences savep;
SharedPreferences.Editor editor;
public ListAdapter_home(Context context, int resource) {
super(context, resource);
contect = context;
}
static class DataHandler {
CustomTextView name;
}
@Override
public void add(Object object) {
super.add(object);
list.add(object);
}
@Override
public void remove(Object object) {
super.remove(object);
list.remove(object);
}
@Override
public int getCount() {
return this.list.size();
}
@Override
public Object getItem(int position) {
return this.list.get(position);
}
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
View row;
row = convertView;
savep = getContext().getSharedPreferences("MySave", getContext().MODE_PRIVATE);
editor = savep.edit();
final DataHandler handler;
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflater.inflate(R.layout.home_card, parent, false);
handler = new DataHandler();
handler.name = (CustomTextView) row.findViewById(R.id.catname);
row.setTag(handler);
} else {
handler = (DataHandler) row.getTag();
}
Log.d("position",""+position);
final HomeList dataProvider;
dataProvider = (HomeList) this.getItem(position);
handler.name.setText(dataProvider.getName());
return row;
}}