ListView的变化记录在滚动 [英] ListView changes records while scrolling

查看:101
本文介绍了ListView的变化记录在滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我怎么看我的屏幕上的页面加载时。但是,当我开始滚动列表,我所有的记录开始改变,变得很奇怪。我真的不知道是什么原因,有什么建​​议?

这是屏幕后,我通过我的的ListView 上下滚动。

适配器:

 私有类TechnicalDocumentationAdapter扩展
        ArrayAdapter< TechnicalDocumentation> {    私人的ArrayList< TechnicalDocumentation>项目;    公共TechnicalDocumentationAdapter(上下文的背景下,
            INT textViewResourceId,ArrayList的< TechnicalDocumentation>项目){
        超(背景下,textViewResourceId,项目);
        this.items =物品;
    }    @覆盖
    公共查看getView(INT位置,查看convertView,父母的ViewGroup){
        视图V = convertView;
        如果(V == NULL){
            LayoutInflater VI =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            V = vi.inflate(R.layout.technicaldocumentationrow,NULL);
        }
        TechnicalDocumentation technicalDocumentation = items.get(位置);
        如果(technicalDocumentation!= NULL){
            TextView的TT =(TextView中)v.findViewById(R.id.TDRdate);
            TextView的BT =(TextView中)v.findViewById(R.id.TDRobjectType code);
            TextView的CT =(TextView的)V
                    .findViewById(R.id.TDRperformedAction);
            在TextView中=(TextView中)v.findViewById(R.id.TDRobjectName);            tt.setText(tt.getText()+\\ n+ technicalDocumentation.date);
            bt.setText(bt.getText()+\\ n
                    + technicalDocumentation.objectType code);
            ct.setText(ct.getText()+\\ n
                    + technicalDocumentation.performedAction);
            at.setText(at.getText()+\\ n
                    + technicalDocumentation.objectName);        }
        返回伏;
    }
}


解决方案

Android的ListView中回收的意见。目前的问题是,你的适配器始终追加新数据TextViews。现在,一个新的行显示每一次,你是从新行的数据附加到旧数据。

要解决这个问题,你应该从旧的数据,如果您使用的是convertView参数清除TextViews。

This is how I see my screen the when the page loads. But when I start scrolling through the list, all my records start to change and it becomes really weird. I really don't know why, any suggestions?

This is the screen after I scroll through my ListView up and down.

Adapter:

private class TechnicalDocumentationAdapter extends
        ArrayAdapter<TechnicalDocumentation> {

    private ArrayList<TechnicalDocumentation> items;

    public TechnicalDocumentationAdapter(Context context,
            int textViewResourceId, ArrayList<TechnicalDocumentation> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.technicaldocumentationrow, null);
        }
        TechnicalDocumentation technicalDocumentation = items.get(position);
        if (technicalDocumentation != null) {
            TextView tt = (TextView) v.findViewById(R.id.TDRdate);
            TextView bt = (TextView) v.findViewById(R.id.TDRobjectTypeCode);
            TextView ct = (TextView) v
                    .findViewById(R.id.TDRperformedAction);
            TextView at = (TextView) v.findViewById(R.id.TDRobjectName);

            tt.setText(tt.getText() + "\n " + technicalDocumentation.date);
            bt.setText(bt.getText() + "\n "
                    + technicalDocumentation.objectTypeCode);
            ct.setText(ct.getText() + "\n "
                    + technicalDocumentation.performedAction);
            at.setText(at.getText() + "\n "
                    + technicalDocumentation.objectName);

        }
        return v;
    }
}

解决方案

Android ListView recycles views. At the moment the problem is that your adapter always appends new data to the TextViews. Now every time a new row is shown, you are appending the data from the new row to the old data.

To solve this, you should clear the TextViews from the old data if you are using the convertView parameter.

这篇关于ListView的变化记录在滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆