TwoWayView delaying the drawing



  • Hello, everyone.
    For a horizontal list, use traces https://github.com/lucasr/twoway-view ♪

    When it starts, it's prepared like this:

        void initSelector(DateTime time, int countDays) {
        DateTime selectorDate = time;
        ArrayList<String> list_days = new ArrayList<>();
    
    if (countDays == 7) {
    
        list_days.add("Пн\n" + selectorDate.withDayOfWeek(1).getDayOfMonth());
        list_days.add("Вт\n" + selectorDate.withDayOfWeek(2).getDayOfMonth());
        list_days.add("Ср\n" + selectorDate.withDayOfWeek(3).getDayOfMonth());
        list_days.add("Чт\n" + selectorDate.withDayOfWeek(4).getDayOfMonth());
        list_days.add("Пт\n" + selectorDate.withDayOfWeek(5).getDayOfMonth());
        list_days.add("Суб\n" + selectorDate.withDayOfWeek(6).getDayOfMonth());
        list_days.add("Вс\n" + selectorDate.withDayOfWeek(7).getDayOfMonth());
    
        selectorAdapter = new SelectorAdapter(getActivity(), list_days, new DateTime().getDayOfWeek() - 1);
    
        lvTest.setAdapter(selectorAdapter);
        selectorAdapter.setCallback(new CallbackOnClick() {
            @Override
            public void onClick(Object param) {
                // Logi.d("param = " + param);
                selectorAdapter.setSelection((int) param);
                guide_list.setSelectedGroup((int) param);
                test_booelan = false;
            }
        });
        //  selectorAdapter.setSelection(new DateTime().getDayOfWeek() - 1);
    } else {
        //lvTest.scrollTo(0,0);
    
        String day_name = "";
        int selection = 0;
        for (int i = 0; i &lt; countDays; i++) {
            switch (selectorDate.getDayOfWeek() - 1) {
                case 0:
                    day_name = "Пн\n";
                    break;
                case 1:
                    day_name = "Вт\n";
                    break;
                case 2:
                    day_name = "Ср\n";
                    break;
                case 3:
                    day_name = "Чт\n";
                    break;
                case 4:
                    day_name = "Пт\n";
                    break;
                case 5:
                    day_name = "Суб\n";
                    break;
                case 6:
                    day_name = "Вс\n";
                    break;
            }
    
            list_days.add(day_name + "" + selectorDate.getDayOfMonth());
            if (selectorDate.getDayOfMonth() == new DateTime().getDayOfMonth()) {
                //selection = i;
                selection = selectorDate.getDayOfWeek() - 1;
                //Logi.d("selection sadas=" + selection);
            }
    
            selectorDate = selectorDate.plusDays(1);
    
        }
    
        selectorAdapter = new SelectorAdapter(getActivity(), list_days, selection + 7);
        //selectorAdapter.setSelection(selection+6);
        selectorAdapter.setSelection(selection + 7);
        lvTest.setAdapter(selectorAdapter);
        selectorAdapter.setCallback(new CallbackOnClick() {
            @Override
            public void onClick(Object param) {
                selectorAdapter.setSelection((int) param);
                guide_list.setSelectedGroup((int) param);
                test_booelan = false;
            }
        });
        Logi.d("selection = "+selection);
    
        lvTest.setSelection(selection + 7);
        lvTest.refreshDrawableState();
        lvTest.invalidate();
        lvTest.setVisibility(View.GONE);
        lvTest.setVisibility(View.VISIBLE);
    

    /*
    selectorAdapter.notifyDataSetChanged();
    lvTest.refreshDrawableState();
    lvTest.invalidate();*/
    }

    }

    SelectorAdapter A castom expansion of the conventional BaseAdapter's.
    The problem is, when the list is downloaded to 14 positions, the last element chosen is to be illuminated in case of a choice, as soon as I try to cover the list, it immediately draws the right position on the list. I've been looking at an idiosynctic of the imaginary, and it's normal if I can drop the code of the adapter. Who knows what the problem is and how to fight it?



  • The mistake was in the Adapter. I've chosen to choose the list item by matching the source list and the row of the list. Rewrite the method by which I define the list for selection as follows:

       void initSelector(DateTime time, int countDays) {
        DateTime selectorDate = time;
        ArrayList<String> list_days = new ArrayList<>();
    
    if (countDays == 7) {
    
        list_days.add("Пн\n" + selectorDate.withDayOfWeek(1).getDayOfMonth());
        list_days.add("Вт\n" + selectorDate.withDayOfWeek(2).getDayOfMonth());
        list_days.add("Ср\n" + selectorDate.withDayOfWeek(3).getDayOfMonth());
        list_days.add("Чт\n" + selectorDate.withDayOfWeek(4).getDayOfMonth());
        list_days.add("Пт\n" + selectorDate.withDayOfWeek(5).getDayOfMonth());
        list_days.add("Суб\n" + selectorDate.withDayOfWeek(6).getDayOfMonth());
        list_days.add("Вс\n" + selectorDate.withDayOfWeek(7).getDayOfMonth());
    
        selectorAdapter = new SelectorAdapter(getActivity(), list_days, new DateTime().getDayOfWeek() - 1);
    
        lvTest.setAdapter(selectorAdapter);
        selectorAdapter.setCallback(new CallbackOnClick() {
            @Override
            public void onClick(Object param) {
                // Logi.d("param = " + param);
                selectorAdapter.setSelection((int) param);
                guide_list.setSelectedGroup((int) param);
                test_booelan = false;
            }
        });
        //  selectorAdapter.setSelection(new DateTime().getDayOfWeek() - 1);
    } else {
        //lvTest.scrollTo(0,0);
        String cur_name="";
        String day_name = "";
        int selection = 0;
        for (int i = 0; i &lt; countDays; i++) {
            switch (selectorDate.getDayOfWeek() - 1) {
                case 0:
                    day_name = "Пн\n";
                    break;
                case 1:
                    day_name = "Вт\n";
                    break;
                case 2:
                    day_name = "Ср\n";
                    break;
                case 3:
                    day_name = "Чт\n";
                    break;
                case 4:
                    day_name = "Пт\n";
                    break;
                case 5:
                    day_name = "Суб\n";
                    break;
                case 6:
                    day_name = "Вс\n";
                    break;
            }
    
            list_days.add(day_name + "" + selectorDate.getDayOfMonth());
            if (selectorDate.getDayOfMonth() == new DateTime().getDayOfMonth()) {
                //selection = i;
                selection = selectorDate.getDayOfWeek() - 1;
                cur_name = day_name + "" + selectorDate.getDayOfMonth();
                //Logi.d("selection sadas=" + selection);
            }
    
            selectorDate = selectorDate.plusDays(1);
    
        }
    
        selectorAdapter = new SelectorAdapter(getActivity(), list_days, selection + 7);
        //selectorAdapter.setSelection(selection+6);
        selectorAdapter.setSelection(selection + 7);
        selectorAdapter.setTextSelectDay(cur_name);
        lvTest.setAdapter(selectorAdapter);
        selectorAdapter.setCallback(new CallbackOnClick() {
            @Override
            public void onClick(Object param) {
                selectorAdapter.setSelection((int) param);
                guide_list.setSelectedGroup((int) param);
                test_booelan = false;
            }
        });
        Logi.d("selection = "+selection);
    
        lvTest.setSelection(selection + 7);
        selectorAdapter.notifyDataSetChanged();
    

    /*
    selectorAdapter.notifyDataSetChanged();
    lvTest.refreshDrawableState();
    lvTest.invalidate();*/
    }

    }

    And the adapter added a variable line and rewrited the method getView:

      String textSelectDay="";

    public String getTextSelectDay() {
    return textSelectDay;
    }

    public void setTextSelectDay(String textSelectDay) {
    this.textSelectDay = textSelectDay;
    }

    ♪ ♪ ♪ ♪

        int innerPosotion=0;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    innerPosotion = position;
    Logi.d("position = "+position);

    View retval = LayoutInflater.from(parent.getContext()).inflate(R.layout.selector_item_layout, null);
    
    
    TextView title = (TextView) retval.findViewById(R.id.title);
    RelativeLayout container = (RelativeLayout)retval.findViewById(R.id.container_inner);
    
    container.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            callback.onClick(innerPosotion);
        }
    });
    
    title.setText((String)getItem(position));
    
    if(textSelectDay.equals(list.get(position))){//selection == position
        container.setBackgroundResource(R.drawable.oval);
        title.setTextColor(Color.WHITE);
    }/* else {
        container.setBackgroundColor(Color.parseColor("#ffffff"));
        title.setTextColor(Color.BLACK);
    }*/
    
    if (retval != null) {
        Logi.d("retval!= null");
        return retval;
    }  else {
        Logi.d("reval == null");
        return new ViewGroup(mContext) {
            @Override
            protected void onLayout(boolean changed, int l, int t, int r, int b) {
    
            }
        };
    }
    

    }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2