1

--- Code ---

public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    ViewHolder vHolder=null;

    if (view  == null) {
        view                 = LayoutInflater.from(context).inflate(R.layout.drawer, null, false);
        vHolder              = new ViewHolder();
        TextView tCategory   = (TextView) view.findViewById(R.id.category);
        TextView tPosition   = (TextView) view.findViewById(R.id.position);
        vHolder.tCategory    = tCategory;
        vHolder.tPosition    = tPosition;
        view.setTag(vHolder);
    }else {
        vHolder = (ViewHolder) view.getTag();
    }

    String[] split     = getItem(position).split("£");
    String   category  = split[0].trim();
    Integer  catID     = Integer.parseInt(split[1].trim());

    vHolder.tCategory.setTag(catID);
    vHolder.tPosition.setTag(catID + "_position");

    if(SZ.CURRENTCATEGORY == catID) {
        vHolder.tCategory.setText("TOP: " + category);
    }else{
        vHolder.tCategory.setText(category);
    }

    AbsListView.LayoutParams params = (AbsListView.LayoutParams) view.getLayoutParams();
    if(catID >= 90){//SUBJECT
        vHolder.tCategory.setTextSize( context.getResources().getDimension(R.dimen.drawer_subject));
        vHolder.tCategory.setTextColor(context.getResources().getColor(R.color.drawer_subject));
        vHolder.tCategory.setTypeface(null, Typeface.BOLD);
        vHolder.tCategory.setGravity(Gravity.CENTER_HORIZONTAL);
        vHolder.tCategory.setPadding(5, 0, 20, 0);

        view.setPressed(false);
        view.setBackgroundColor(Color.DKGRAY);
        vHolder.tPosition.setVisibility(View.GONE);
    }else{//CATEGORY
        if (vHolder.tPosition.getText().toString().trim().equalsIgnoreCase("") && vHolder.tPosition.getText().toString().indexOf("0") == -1) {
            vHolder.tPosition.setText("0");
            int position = SZ.position(catID);
            if (position > 0) {
                vHolder.tPosition.setText("" + position);
            }
        }
        vHolder.tPosition.setVisibility(View.VISIBLE);
        vHolder.tCategory.setTextSize(context.getResources().getDimension(R.dimen.drawer_category));
        vHolder.tCategory.setTextColor(context.getResources().getColor(R.color.drawer_category));
        vHolder.tCategory.setTypeface(null, Typeface.NORMAL);
        vHolder.tCategory.setGravity(Gravity.NO_GRAVITY);
        vHolder.tCategory.setPadding(0, 5, 0, 0);

        view.setPressed(true);
        view.setBackgroundColor(Color.TRANSPARENT);
    }

    return view;
}

I was run my code on Android Emulator. When i open my navigation drawer anythings work normally but when i scroll down on the list or scroll up my category position value (vHolder.tPosition) changing abnormaly..

I search more time for this problem and i use ViewHolder pattern but not solved. So how i can solved this problem? (Thank you)

Sory for my bad english.

kibar
  • 822
  • 3
  • 17
  • 37
  • can u post comeplete java file plz? – KOTIOS May 10 '14 at 18:41
  • Try to put all the code between `String[] split` and `vHolder.tPosition.setTag(catID + "_position");` inside the `f (view == null)` – Alejandro Alcalde May 10 '14 at 18:43
  • What's the exact abnormal behavior? Also, if you're using ListView, viewholder pattern shouldn't be needed. –  May 10 '14 at 18:53
  • Monicka, file to big :(, algui91, not working but thank you – kibar May 10 '14 at 18:54
  • @Messer Why ViewHolder is not necessary? – Alejandro Alcalde May 10 '14 at 18:55
  • @Messer (without ViewHolder) when i scroll down to list all object(Text view etc) changing abnormally text etc. So i see ViewHolder pattern and use it i hope because more problem solved. But now only i have this problem; When i open my drawer everythings okey. but when i scroll down to bottom; My first object go to bottom(vHolder.tPosition), when i scroll up to top my last object go to first(vHolder.tPosition) – kibar May 10 '14 at 18:59
  • now solved this problem, ty all :) http://stackoverflow.com/questions/9188201/list-view-position-is-getting-changed-when-scrolling-on-android?rq=1 – kibar May 10 '14 at 19:28

0 Answers0