mostrar la información del usuario en el fragmento

Mohamed:

Estoy usando Android Studio 3.5.

Construí de navegación inferior con el fragmento y luego estoy tratando de pantalla de información del usuario como (nombre - email - imagen y así sucesivamente) que se recupera de una tienda Firebase .. cuando alcance a:

documentReference.addSnapshotListener (this, new EventListener<DocumentSnapshot>() {
    @Override
    public void onEvent(@Nullable DocumentSnapshot documentSnapshot, 
            @Nullable FirebaseFirestoreException e) {
        t_name.setText(documentSnapshot.getString("name"));
        t_email.setText(documentSnapshot.getString("email"));
    }
});

Me dio una línea roja bajo el código ... Cuando clic Alt+ Enter, da a resolver fundido put (Ejecutor) antes (este) después de que el elenco de la aplicación no funciona ...

línea roja

No sé cómo resolverlo ..

Nota: Este es el fragmento no en la actividad

Y si quiero mostrar la imagen que recuperar de Firebase ... ¿Cómo puedo hacerlo?

Gracias

Fragmento cuenta

public class accountFragment extends Fragment {
    FirebaseAuth fAuth;
    FirebaseFirestore fStore;
    String userID;
    TextView logout_account , t_name , t_email , t_country ;

    public  accountFragment(){
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_account, container, false);

    fAuth = FirebaseAuth.getInstance();
    fStore = FirebaseFirestore.getInstance();
    userID = fAuth.getCurrentUser().getUid();

    t_country = v.findViewById(R.id.t_country);
    t_email = v.findViewById(R.id.t_email);
    t_name = v.findViewById(R.id.t_name);

    DocumentReference documentReference = fStore.collection("eng.users").document(userID);
    documentReference.addSnapshotListener (this, new EventListener<DocumentSnapshot>() {
        @Override
        public void onEvent(@Nullable DocumentSnapshot documentSnapshot, 
                @Nullable FirebaseFirestoreException e) {
            t_name.setText(documentSnapshot.getString("name"));
            t_email.setText(documentSnapshot.getString("email"));
            t_country.setText(documentSnapshot.getString("country"));
        }
    });
}

Activity_account.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".categories.accountFragment">


    <LinearLayout
    android:id="@+id/banner_pro"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="@drawable/banner2"
    android:orientation="horizontal"
    android:paddingLeft="50dp"
    android:paddingTop="10dp">


    <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/profile_image"
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:src="@drawable/mypic"
    app:civ_border_color="@color/colorDarkBlue"
    app:civ_border_width="2dp" />

    <LinearLayout
    android:layout_marginTop="20dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingLeft="20dp"
    >

    <TextView
    android:textColor="@color/colorDarkBlue"
    android:id="@+id/t_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Name"
    android:textSize="20dp"
    android:textStyle="bold"/>

    <TextView
    android:id="@+id/t_email"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="9dp"
    android:text="Email"
    android:textSize="15dp" />

    <TextView
    android:id="@+id/t_country"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:text="country"
    android:textSize="15dp" />

    </LinearLayout>

    </LinearLayout>

    <TextView
    android:paddingLeft="20dp"
    android:id="@+id/logout_account"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/banner_pro"
    android:layout_marginTop="20dp"
    android:text="LogOut"
    android:textSize="30dp" />

</RelativeLayout>
Gastón Saillén :

El problema está en

documentReference.addSnapshotListener (this, ...

utilizar

documentReference.addSnapshotListener (getActivity(), ...

Usted está en un fragmento

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=373040&siteId=1
Recomendado
Clasificación