mohamed:
J'utilise Android Studio 3.5.
Je construit la navigation en bas avec le fragment et je suis en train de l'information de l'utilisateur d'affichage tels que (nom - email - image et ainsi de suite) qui est récupéré à partir d'un magasin Firebase .. quand à portée:
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"));
}
});
Il m'a donné une ligne rouge sous le code ... Quand clic Alt+ Enter, il me donne résous casting put (Exécuteur) avant (ce) après la distribution de l'application ne fonctionne pas ...
Je ne sais pas comment le résoudre ..
Note: Ceci est le fragment non de l'activité
Et si je veux afficher l'image que de récupérer Firebase ... Comment puis-je faire?
Merci
compte Fragment
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>
Gaston Saillen:
Le problème est
documentReference.addSnapshotListener (this, ...
utilisation
documentReference.addSnapshotListener (getActivity(), ...
Vous êtes dans un fragment