モハメド:
私は、Android Studioの3.5を使用しています。
私は断片と下部のナビゲーションを構築し、その後、私はそのような(名 - メール - 画像など)などの表示、ユーザー情報にしようとしていたときに到達するために... Firebaseストアから取得されます。
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"));
}
});
これは、クリックすると...私のコードの下に赤い線を与えたAlt+ Enterキャストした後、アプリが仕事をしない、それは私が(この)の前に置くキャスト(エグゼキュータ)を解く与えます...
私はそれを解決する方法がわかりません。..
注:これは、活動に断片上ではありません
私はFirebaseから取得した画像を表示したい場合は...私はそれはどのように行うことができますか?
感謝
アカウントの断片
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>
ガストンSaillen:
問題がオンになっています
documentReference.addSnapshotListener (this, ...
使用する
documentReference.addSnapshotListener (getActivity(), ...
あなたは、フラグメントであります