In Custom ListView ,ArrayAdapter giving wrong position while scrolling

318
June 19, 2017, at 01:44 AM

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;
}}
Rent Charter Buses Company
READ ALSO
Regex for multiple words between special characters

Regex for multiple words between special characters

I'm trying to get every group of words with at least one word between some special characters with a regular expression in JavaThese are some sample strings to clarify it:

364
Method adding element to array of ints

Method adding element to array of ints

I need help with creating a method that adds input int to an array, and returning a message if array is already full

275
How to add multiple database softwares(MySQL , PostgreSQL , Oracle , DB2 , Derby , etc…) in simple java swing project?

How to add multiple database softwares(MySQL , PostgreSQL , Oracle , DB2 , Derby , etc…) in simple java swing project?

I have created a simple java swing project of executing SQL Queries and displaying the results in jTableI have no problem with execution of queries and displaying them

391
Performance Logging with Spring Boot and AOP

Performance Logging with Spring Boot and AOP

I'm trying to implement performance logging based off of this post: http://wwwbaeldung

724