滚动后,Recyclerview数据会被覆盖

时间:2015-05-10 21:03:36

标签: java android android-recyclerview

以下是我的适配器的部分代码:

    public void add(Information info){
        data.add(info);
        notifyItemInserted(data.size()-1);
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=inflater.inflate(R.layout.custom_row, parent,false);
        MyViewHolder holder=new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Information current = data.get(position);

        holder.to.setText(current.getTo());
        holder.from.setText(current.getFrom());
        holder.distance.setText(current.getDistance());
    }

添加行按钮的代码:

mAdapter.add(dataToAdd); 
linearLayoutManager.scrollToPositionWithOffset(mAdapter.getItemCount() - 1, 0);

每当我将数据添加到我的recyclerview时,它都会添加正常,但是当我滚动输入的行开始覆盖所有其他行时,请帮助

编辑: 我使用它的应用程序已经发布,所以我真的需要解决这个问题。

https://play.google.com/store/apps/details?id=dijkstra.tqrapps.com.dijkstra

我在listview中添加了很多数字,但是他们开始覆盖最新的行

更新2:

public class Information {
    private String from,to,distance;

    public Information(){

    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getTo() {
        return to;
    }

    public void setTo(String to) {
        this.to = to;
    }

    public String getDistance() {
        return distance;
    }

    public void setDistance(String distance) {
        this.distance = distance;
    }
}

enter image description here

0 个答案:

没有答案