更新时,RecyclerView重叠数据

时间:2019-03-27 08:32:38

标签: android android-recyclerview recycler-adapter

获取<glassfish-web-app error-url=""> <context-root>/hr</context-root> <class-loader delegate="true"/> <property name="alternatedocroot_1" value="from=/pictures/* dir=/Projects/hr-pictures" /> <jsp-config> ... </jsp-config> </glassfish-web-app> 中的数据时遇到问题。如果添加数据,则我的数据已更新,但会相互重叠。下面是我为实现相同目的而实现的代码:

RecyclerView

这是我为recyclerview编写的适配器:

@Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getActivity().setTitle("Schedule");

           ArrayList<ScheduleDisplayDetails> get = new ArrayList<>();
                    while (c.moveToNext()) {
                        ScheduleDisplayDetails details = new ScheduleDisplayDetails();
                        details.setID(c.getString(c.getColumnIndexOrThrow("ScheduleId")));
                        details.setLocation(c.getString(c.getColumnIndexOrThrow("ScheduleLocation")));
                        details.setLatitude(c.getString(c.getColumnIndexOrThrow("ScheduleLatitude")));
                        details.setExpectedTimeOfTransaction(c.getString(c.getColumnIndexOrThrow("ScheduleExpectedTimeOfTransaction")));
                        details.setEstimatedTimeOfDeparture(c.getString(c.getColumnIndexOrThrow("ScheduleEstimatedTimeOfDeparture")));
                        details.setLongitude(c.getString(c.getColumnIndexOrThrow("ScheduleLongitude")));
                        details.setStatus(c.getString(c.getColumnIndexOrThrow("ScheduleStatus")));
                        get.add(details);
                    }
                    layoutManager = new LinearLayoutManager(getContext());
                    RecyclerView recyclerView = inflatedView.
                            findViewById(R.id.scheduleRecycler);
                    recyclerView.setLayoutManager(layoutManager);
                    recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.VERTICAL));

                    ScheduleModuleAdapter recyclerViewAdapter =
                            new ScheduleModuleAdapter(get);

                    recyclerView.setAdapter(recyclerViewAdapter);

这是我用来处理异常的costumizeExemptionHandler(design)。

             private List<NavDrawerFleetGetterSetter> navlist;

    public class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView lat, lon, dateTime;


        public MyViewHolder(View view) {
            super(view);
            lat = view.findViewById(R.id.non_map_lat);
            lon = view.findViewById(R.id.non_map_lon);
            dateTime = view.findViewById(R.id.non_map_date_time);

        }
    }


    public NavDrawerFleetAdapter(List<NavDrawerFleetGetterSetter> navDrawerList) {
        this.navlist = navDrawerList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.nav_drawer_non_map_card_view, parent, false);

        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        NavDrawerFleetGetterSetter sched = navlist.get(position);
        holder.lat.setText(sched.getLat());
        holder.lon.setText(sched.getLon());
        holder.dateTime.setText(sched.getDateTime());

    }

    @Override
    public int getItemCount() {
        return navlist.size();
    }

这是我的更新(一次): enter image description here

这是我的两次更新请求: enter image description here

这是我针对多个请求的更新: enter image description here

0 个答案:

没有答案