mohamed :
I'm using Android Studio 3.5.
I built bottom navigation with fragment and then I'm trying to display user information such as (name - email - image and so on) that is retrieved from a Firebase store .. when reach to :
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"));
}
});
It gave me a red line under the code... When click Alt + Enter, it gives me solve put cast (Executor) before (this) after the cast the app doesn't work ...
I don't know how to solve it ..
Note: This is on fragment not in activity
And if I want to display image that retrieve from Firebase... How can I do it?
Thanks
account 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>
Gastón Saillén :
The problem is on
documentReference.addSnapshotListener (this, ...
use
documentReference.addSnapshotListener (getActivity(), ...
You are in a fragment
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=371924&siteId=1