Проблемы с настройкой ImageView на Gridview во фрагменте - PullRequest
0 голосов
/ 26 декабря 2018

Я пытаюсь создать календарь, следуя настроенному календарю брата разработчика. Я использую фрагменты, но ничего не получается, когда я нажимаю на сетку, я хочу установить Imageview в фоновом режиме.

thisмой xml для каждого элемента gridview.

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:background="#ffffff"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="4dp" >

    <android.support.constraint.ConstraintLayout
        android:id="@+id/diseno_item_calendario"
        android:layout_width="30dp"
        android:layout_height="39dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="vertical"
        android:padding="1dp">

        <ImageView
            android:id="@+id/fecha_hoy"
            android:layout_width="23dp"
            android:layout_height="22dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginBottom="16dp"
            android:layout_marginTop="6dp"
            android:src="@drawable/dotyellow"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.571"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:visibility="invisible"
            />

        <TextView
            android:id="@+id/date"
            android:layout_width="17dp"
            android:layout_height="14dp"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="2dp"
            android:paddingLeft="3dp"
            android:text="15"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.63"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/fecha_hoy"
            app:layout_constraintVertical_bias="0.0" />

        <ImageView
            android:id="@+id/date_icon"
            android:layout_width="wrap_content"
            android:layout_height="6dp"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="10dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.521"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/date"
            app:layout_constraintVertical_bias="0.0"
            app:srcCompat="@drawable/dot"
            android:visibility="invisible"/>


    </android.support.constraint.ConstraintLayout>

</LinearLayout>

Это java для фрагмента ..

public class TallerFragment extends Fragment {

    public GregorianCalendar cal_month, cal_month_copy;
    private CalendarioAdapter calendarioAdapter;
    private TextView tv_month;
    public String selectedGridDate;
    private ImageView clickEnFecha;


    public TallerFragment() {
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {



        final View calendarFragment=inflater.inflate(R.layout.fragment_taller,container,false);

        clickEnFecha=(ImageView)calendarFragment.findViewById(R.id.fecha_hoy);


                DatosSeguimiento.datosSeguimientoArrayList=new ArrayList<DatosSeguimiento>();

        //Datos Quemados

        DatosSeguimiento.datosSeguimientoArrayList.add(new DatosSeguimiento("19/12/2018","18/12/2018","5464353453654","Hola mundo"));

        cal_month = (GregorianCalendar) GregorianCalendar.getInstance();
        cal_month_copy = (GregorianCalendar) cal_month.clone();
        calendarioAdapter = new CalendarioAdapter(getActivity(), cal_month, DatosSeguimiento.datosSeguimientoArrayList);

        tv_month = (TextView) calendarFragment.findViewById(R.id.tv_month);
        tv_month.setText(android.text.format.DateFormat.format("MMMM yyyy", cal_month));


        ImageButton previous = (ImageButton) calendarFragment.findViewById(R.id.ib_prev);
        previous.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (cal_month.get(GregorianCalendar.MONTH) == 4&&cal_month.get(GregorianCalendar.YEAR)==2017) {
                    //cal_month.set((cal_month.get(GregorianCalendar.YEAR) - 1), cal_month.getActualMaximum(GregorianCalendar.MONTH), 1);
                    Toast.makeText(getActivity(), "Event Detail is available for current session only.", Toast.LENGTH_SHORT).show();
                }
                else {
                    setPreviousMonth();
                    refreshCalendar();
                }


            }
        });
        ImageButton next = (ImageButton) calendarFragment.findViewById(R.id.Ib_next);
        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (cal_month.get(GregorianCalendar.MONTH) == 5&&cal_month.get(GregorianCalendar.YEAR)==2018) {
                    //cal_month.set((cal_month.get(GregorianCalendar.YEAR) + 1), cal_month.getActualMinimum(GregorianCalendar.MONTH), 1);
                    Toast.makeText(getActivity(), "Event Detail is available for current session only.", Toast.LENGTH_SHORT).show();
                }
                else {
                    setNextMonth();
                    refreshCalendar();
                }
            }
        });
        GridView gridview = (GridView) calendarFragment.findViewById(R.id.gv_calendar);
        gridview.setAdapter(calendarioAdapter);
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                selectedGridDate = calendarioAdapter.day_string.get(position);
                Log.d("TAG","Posicion en el grid:---->>>"+selectedGridDate);
                ((CalendarioAdapter) parent.getAdapter()).getPositionList(selectedGridDate, getActivity());
                Date currentTime = Calendar.getInstance().getTime();
                Log.d("TAG","Fecha y hora actual:---->>>"+currentTime);


                //clickEnFecha.setVisibility(calendarFragment.VISIBLE);
                clickEnFecha.setVisibility(v.VISIBLE);

            }

        });
        return calendarFragment;
    }
    protected void setNextMonth() {
        if (cal_month.get(GregorianCalendar.MONTH) == cal_month.getActualMaximum(GregorianCalendar.MONTH)) {
            cal_month.set((cal_month.get(GregorianCalendar.YEAR) + 1), cal_month.getActualMinimum(GregorianCalendar.MONTH), 1);
        } else {
            cal_month.set(GregorianCalendar.MONTH,
                    cal_month.get(GregorianCalendar.MONTH) + 1);
        }
    }

    protected void setPreviousMonth() {
        if (cal_month.get(GregorianCalendar.MONTH) == cal_month.getActualMinimum(GregorianCalendar.MONTH)) {
            cal_month.set((cal_month.get(GregorianCalendar.YEAR) - 1), cal_month.getActualMaximum(GregorianCalendar.MONTH), 1);
        } else {
            cal_month.set(GregorianCalendar.MONTH, cal_month.get(GregorianCalendar.MONTH) - 1);
        }
    }

    public void refreshCalendar() {
        calendarioAdapter.refreshDays();
        calendarioAdapter.notifyDataSetChanged();
        tv_month.setText(android.text.format.DateFormat.format("MMMM yyyy", cal_month));
    }

    }

Что я хочу сделать, это когда пользователь нажимает на gridview вв любой позиции он устанавливает фон с помощью рисования.

...