Make Final Android Studio - PullRequest
       64

Make Final Android Studio

0 голосов
/ 24 марта 2020

Я слежу за видео онлайн, но застрял с этим, когда не могу сделать переменную окончательной. Этот код выполняется в android studio.

ошибка: невозможно найти переменную символа i

Ошибка может быть найдена в последней 5 строке.

intent.putExtra(Common.KEY_TIME_SLOT, i);

Единственный вариант, который у меня есть:

  • Создать локальную переменную
  • Создать поле
  • Создать параметр
  • Переименовать ссылку

Вот весь код:

@Override

    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.txt_time_slot.setText(new StringBuilder(Common.convertTimeSlotToString(position)).toString());
        if(timeSlotList.size()==0)//if all is available, show list
        {
            holder.card_time_slot.setCardBackgroundColor(context.getResources().getColor(android.R.color.white));
            holder.txt_time_slot_description.setText("Available");
            holder.txt_time_slot_description.setTextColor(context.getResources().getColor(android.R.color.black));
            holder.txt_time_slot.setTextColor(context.getResources().getColor(android.R.color.black));
        }
        else //if fully booked
        {
            for(TimeSlot slotValue:timeSlotList)
            {
                //loop all time slot from sever and set different color
                int slot = Integer.parseInt(slotValue.getSlot().toString());
                if(slot==position) // if slot == position
                {
                    holder.card_time_slot.setTag(Common.DISABLE_TAG);
                    holder.card_time_slot.setCardBackgroundColor(context.getResources().getColor(android.R.color.darker_gray));
                    holder.txt_time_slot_description.setText("BOOKED");
                    holder.txt_time_slot_description.setTextColor(context.getResources()
                            .getColor(android.R.color.white));
                    holder.txt_time_slot.setTextColor(context.getResources().getColor(android.R.color.white));

                }
            }
        }

        //add available time slot
        if (!cardViewList.contains(holder.card_time_slot))
            cardViewList.add(holder.card_time_slot);
        //check if slot is available
        holder.setiRecyclerItemSelectedListener(new IRecyclerItemSelectedListener() {
            @Override
            public void onItemSelectedListener(View view, int pos) {
                //loop all slots
                for(CardView cardView:cardViewList)
                {
                    if (cardView.getTag() == null)
                        cardView.setCardBackgroundColor(context.getResources()
                                .getColor(android.R.color.white));
                }
                //selected slot will change color
                holder.card_time_slot.setCardBackgroundColor(context.getResources()
                .getColor(android.R.color.holo_orange_dark));

                //once selected, send signal to next button
                Intent intent = new Intent(Common.KEY_ENABLE_BUTTON_NEXT);
                intent.putExtra(Common.KEY_TIME_SLOT, i); // error. in the video it shows that i can make "i" final but on my end it does not show that option.
                intent.putExtra(Common.KEY_STEP,3); //going step 3
                localBroadcastManager.sendBroadcast(intent);
            }
        });

Ответы [ 2 ]

0 голосов
/ 24 марта 2020

Ошибка говорит, что «не может найти переменную символа i», сначала нужно создать переменную и сделать ее окончательной: final int i = 0;

0 голосов
/ 24 марта 2020

Проблема не в том, что он не является окончательным (что можно сделать переменной final, введя перед ней слово final). Проблема в том, что он вообще не существует. У вас нет нигде переменной с именем i.

Возможно, я должен был быть pos, элемент, который был фактически выбран.

...