Раздуйте 2 макета в одном фрагменте, чтобы обновить TextView - android - PullRequest
0 голосов
/ 20 февраля 2020

Я пытаюсь обновить TextView с текстом в методе. Основная функция метода - накачать макет с помощью RecyclerView и обновить эти представления значениями из firestore. Мой RecyclerView также имеет прикрепленный ItemDecoration, который имеет свой собственный макет. В этом методе я также хочу обновить текстовое представление этого макета. Я попытался создать отдельный вид и накачать макет ItemDecoration, найти TextView и обновить текст, но текст не обновляется при запуске.

Метод OnCreate

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

        v = inflater.inflate(R.layout.galway_fragment, container, false);

        recyclerView = (RecyclerView) v.findViewById(R.id.galway_recycler);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.setHasFixedSize(true);
        MyAdapter adapter = new MyAdapter(placeNames);

        recyclerView.addItemDecoration(HeaderDecoration.with(recyclerView)
                .inflate(R.layout.stamp_header)
                .parallax(0.2f)
                .dropShadowDp(4)
                .build());

        recyclerView.setAdapter(adapter);

        db.collection("galway")
                .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                        for (QueryDocumentSnapshot document : task.getResult()) {
                            placeNames.add(document.getData().get("Name").toString());
                        }
                        adapter.notifyDataSetChanged();
                    }
                });
        View v2 = inflater.inflate(R.layout.stamp_header, container, false);
        TextView header = (TextView) v2.findViewById(R.id.header);
        Log.i("HEADER", header.toString());
        header.setText("GALWAY");

        return v;
    }

galway_fragment - это макет RecyclerView, который определяет макет для данных fireStore, placeNames . Макет ItemDecoration определяется stamp_header , который я пытаюсь установить в качестве теста "GALWAY" в TextView.

galway_fragment

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/galway_recycler"/>
</LinearLayout>

stamp_header

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:background="@color/red"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:padding="16dp"
        android:textSize="30sp"
        android:text="HI THERE" />


</RelativeLayout>

Stamp_header - это второй макет, который я хочу обновить Text. Благодарю за любую помощь !!

...