滚动时可扩展的listview丢失数据

时间:2018-06-13 13:24:11

标签: android scroll expandablelistview expandablelistadapter

在可扩展列表视图中滚动时,子视图正在丢失其原始位置数据。

这里我在滚动前附加显示输出的图像。

enter image description here

N这是另一张显示滚动后输出的图像。

enter image description here

正如您所见,6月11日的数据丢失了。深灰色背景子视图可能导致此问题。因为该布局是动态膨胀的,所以取决于arraylist中的数据数量。对于其他日期,如6月12日,此深灰色背景数据也可以为空。对于此类日期,将禁用深灰色背景子布局。

适配器文件:

 public class MyTeamScheduleExpandableListAdapter extends BaseExpandableListAdapter {

    private Context context;
    private ArrayList<Emp_List_Shift_items> emp_list_shift_itemes = new ArrayList<Emp_List_Shift_items>();
    TextView details_additional;
    SessionManager session;
    String Emp;

    LayoutInflater layoutInflater;


    public MyTeamScheduleExpandableListAdapter(Context applicationContext, ArrayList<Emp_List_Shift_items> emp_list_shift_itemes, String forDate) {
        session = new SessionManager(applicationContext);
        layoutInflater = LayoutInflater.from(applicationContext);

        this.context = applicationContext;
        this.emp_list_shift_itemes = emp_list_shift_itemes;
    }


    @Override
    public Object getChild(int listPosition, int expandedListPosition) {

        this.notifyDataSetChanged();

        ArrayList<ShiftList_items> shiftList_itemses = emp_list_shift_itemes.get(listPosition).getItems();
        return shiftList_itemses.get(expandedListPosition);
    }

    @Override
    public long getChildId(int listPosition, int expandedListPosition) {

        return expandedListPosition;
    }


    @Override
    public View getChildView(int listPosition, final int expandedListPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;

        this.notifyDataSetChanged();
        ShiftList_items shiftList_items = (ShiftList_items) getChild(listPosition, expandedListPosition);

        Log.d("getDetails",shiftList_items.getDetails());
        Log.d("getForDate",shiftList_items.getForDate());


        if (convertView == null) {
            viewHolder = new ViewHolder();

            layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.my_schedule_listview, null);

            viewHolder.expandedListTextView = (TextView) convertView.findViewById(R.id.ForDate);
            viewHolder.middle_lay = (LinearLayout) convertView.findViewById(R.id.middle_lay);
            viewHolder.details = (TextView) convertView.findViewById(R.id.details);

            convertView.setTag(viewHolder);


        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();

        }


        viewHolder.expandedListTextView.setText(shiftList_items.getForDate());


        if (!shiftList_items.getDetails().equalsIgnoreCase("")) {

            String[] items = shiftList_items.getDetails().split("#");
            List<String> itemList = Arrays.asList(items);

            if (itemList.size() > 1) {
                viewHolder.middle_lay.removeAllViews();
//                viewHolder.forDate.setText(shiftList_itemses.get(position).getForDate());
                for (int i = 0; i < itemList.size(); i++) {


                    String abcd = itemList.get(i);
//                    View line = layoutInflater.inflate(R.layout.schedule_details_list_layout, null);
                    viewHolder.middle_lay.addView(layoutInflater.inflate(R.layout.schedule_details_list_layout, null));
                    details_additional = (TextView) convertView.findViewById(R.id.details);
                    details_additional.setText(abcd);

                }
            } else {

                viewHolder.details.setText(itemList.get(0));
            }

        } else {
            viewHolder.middle_lay.setVisibility(View.GONE);

        }

        return convertView;
    }

    @Override
    public int getChildrenCount(int listPosition) {
//        Toast.makeText(context, "getChildrenCount", Toast.LENGTH_SHORT).show();

        ArrayList<ShiftList_items> shiftList_itemses = emp_list_shift_itemes.get(listPosition).getItems();
        return shiftList_itemses.size();
//        return shiftList_itemses.get(emp_list_shift_itemes.get(listPosition))
//                .size();
    }

    @Override
    public Object getGroup(int listPosition) {
        return emp_list_shift_itemes.get(listPosition);
    }

    @Override
    public int getGroupCount() {
        return emp_list_shift_itemes.size();
    }

    @Override
    public long getGroupId(int listPosition) {
        return listPosition;
    }

    @Override
    public View getGroupView(int listPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
//        String listTitle = (String) getGroup(listPosition);
        Emp_List_Shift_items emp_list_shift_items = (Emp_List_Shift_items) getGroup(listPosition);
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();

            LayoutInflater layoutInflater1 = (LayoutInflater) this.context.
                    getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater1.inflate(R.layout.my_team_schedule_list, null);


            viewHolder.name = (TextView) convertView.findViewById(R.id.name);
            viewHolder.Hours = (TextView) convertView.findViewById(R.id.hours);
            convertView.setTag(viewHolder);

        }
        else {
            viewHolder = (ViewHolder) convertView.getTag();
        }



        viewHolder.name.setTypeface(null, Typeface.BOLD);
        viewHolder.name.setText(emp_list_shift_items.getEmp_Name());
        String hours = "Hours : " + emp_list_shift_items.getTotalHours();
        viewHolder.Hours.setText(hours);
        Emp = emp_list_shift_items.getEmp_id();


        return convertView;
    }

    static class ViewHolder
    {
        TextView Hours,name,expandedListTextView,details;
        LinearLayout middle_lay;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public boolean isChildSelectable(int listPosition, int expandedListPosition) 
    {
        return true;
    }


    }

我已经尝试了很多方法来解决这个问题但没有发生任何事情。

0 个答案:

没有答案