当向下或向上滚动对象改变位置时,Android ArrayAdapter

当向下或向上滚动对象改变位置时,Android ArrayAdapter,android,android-listview,android-arrayadapter,Android,Android Listview,Android Arrayadapter,--代码-- 我在Android模拟器上运行我的代码。当我打开导航抽屉时,任何东西都正常工作,但当我在列表上向下滚动或向上滚动类别位置值vHolder.tPosition异常更改时 我为这个问题搜索了更多的时间,我使用了ViewHolder模式,但没有解决。 那么我怎样才能解决这个问题呢?多谢各位 对不起,我的英语不好。你能发布完整的java文件plz吗?试着把所有代码放在字符串[]split和vHolder.tPosition.setTagcatID+\u position之间;在f视图中==

--代码--

我在Android模拟器上运行我的代码。当我打开导航抽屉时,任何东西都正常工作,但当我在列表上向下滚动或向上滚动类别位置值vHolder.tPosition异常更改时

我为这个问题搜索了更多的时间,我使用了ViewHolder模式,但没有解决。 那么我怎样才能解决这个问题呢?多谢各位


对不起,我的英语不好。

你能发布完整的java文件plz吗?试着把所有代码放在字符串[]split和vHolder.tPosition.setTagcatID+\u position之间;在f视图中==null确切的异常行为是什么?另外,如果您使用的是ListView,则不需要使用viewholder模式。Monicka,文件到大:,algui91,不工作,但谢谢you@Messer为什么不需要ViewHolder?
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;
}