0

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;
}}
user3527444
  • 269
  • 1
  • 4
  • 7
  • There is no guarantee as to the order or number of times `getView()` will be called in an `Adapter`. You shouldn't have any kind of logic there that relies on those things. What is your problem, specifically? – Mike M. Jun 18 '17 at 13:22
  • You probably need to use a holder \ ViewHolder pattern for your ListView. Example: https://stackoverflow.com/questions/15497847/android-secionlist-and-holder?answertab=oldest#tab-top – RonTLV Jun 18 '17 at 13:29
  • @Mike M. The problem is actually getting wrong position on when scrolling bottom to down, If I am set some value for each position its repeat on each 6th position from bottom scroll – user3527444 Jun 18 '17 at 16:13
  • @RonTLV ViewHolder is just class name, here in my case I have already user DataHandler, And also try to use ViewHolder , but no help... – user3527444 Jun 18 '17 at 16:22
  • You'll need to [edit] your question to provide a [mcve] that demonstrates the problem. The code you've posted wouldn't itself be the sole issue. – Mike M. Jun 18 '17 at 16:35

0 Answers0