英文:
My fragment_profile.xml doesnt show. Whats wrong with my program?
问题
I created a new fragment which is ProfileFragment.java and also created fragment_profile.xml.
The program does not give any error but my layout doesn't show. What is wrong?
My ProfileFragment.java:
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;
public class ProfileFragment extends Fragment {
//firebase auth
FirebaseAuth firebaseAuth;
FirebaseUser user;
FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;
//layout views
ImageView avatar;
TextView nameTxt, emailTxt, phoneTxt;
public ProfileFragment() {
//boş public constructor gerekli
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_profile, container, false);
//init firebase
firebaseAuth = FirebaseAuth.getInstance();
user = firebaseAuth.getCurrentUser();
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference("Users");
//init layout views
avatar = view.findViewById(R.id.avatar);
nameTxt = view.findViewById(R.id.nameTxt);
emailTxt = view.findViewById(R.id.emailTxt);
phoneTxt = view.findViewById(R.id.phoneTxt);
/* giriş yapan kullanıcıların bilgilerini email yada uid kullanarak çekmek zorundayız
Kullanıcı detaylarını email adreslerini kullanarak çekeceğiz
orderbyChild query kullanarak giriş yapılan email ile email key ini eşleştirerek kullanıcı detaylarına ulaşılıyor
*/
Query query = databaseReference.orderByChild("email").equalTo(user.getEmail());
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
//gerekli veriler gelene kadar kontrol et
for (DataSnapshot ds: snapshot.getChildren()){
//verileri almak için
String name = ""+ ds.child("name").getValue();
String email = ""+ ds.child("email").getValue();
String phone = ""+ ds.child("phone").getValue();
String image = ""+ ds.child("image").getValue();
//set data
nameTxt.setText(name);
emailTxt.setText(email);
phoneTxt.setText(phone);
try {
// resim alınırsa ayarla
Picasso.get().load(image).into(avatar);
} catch (Exception e){
// resim alınırken herhangi bir sıkıntı varsa varsayılan olarak ayarla
Picasso.get().load(R.drawable.add_photo_foreground).into(avatar);
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
return view;
}
}
and my fragment_profile.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:background="#F1EDED"
tools:context=".ProfileFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="#2ECC71">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:layout_marginTop="100dp">
<ImageView
android:id="@+id/avatar"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/add_photo_foreground"
android:layout_marginStart="20dp"
android:background="#6AE493"
android:padding="5dp">
</ImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/nameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:textSize="25dp"
android:textColor="#FFFFFF"></TextView>
<TextView
android:id="@+id/emailTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:textColor="#FFFFFF"></TextView>
<TextView
android:id="@+id/phoneTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:textColor="#FFFFFF"></TextView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
I want to create a user profile page using Firebase Realtime Database. The user details come from using email for the current signed user. But my profile layout file does not work. How can I fix this problem? What's wrong in my code?
My DashboardActivity.java - For fragment transaction.
package com.gamze.pawsbook;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class DashboardActivity extends AppCompatActivity {
//FirebaseAuth
FirebaseAuth firebaseAuth;
//Actionbar
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
//ActionBar ve başlığı
actionBar = getSupportActionBar();
actionBar.setTitle("Profile");
firebaseAuth = FirebaseAuth.getInstance();
//Bottom navigation
BottomNavigationView navigationView = findViewById(R.id.navigation);
navigationView.setOnNavigationItemSelectedListener(selectedListener);
//Home Fragment'ı boş default fragment olarak ayarlanması
actionBar.setTitle("Home"); //ActionBar başlığını değiştirme
HomeFragment homeFragment = new HomeFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content, homeFragment, "");
ft.commit();
}
// ... (Rest of your code)
}
activity_dashboard.xml
英文:
I created a new fragment which is ProfileFragment.java and also created fragment_profile.xml.
The program does not give any error but my layout doesnt show. What is wrong?
My ProfileFragment.java :
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;
public class ProfileFragment extends Fragment {
//firebase auth
FirebaseAuth firebaseAuth;
FirebaseUser user;
FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;
//layout views
ImageView avatar;
TextView nameTxt, emailTxt, phoneTxt;
public ProfileFragment() {
//boş public constructor gerekli
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_profile, container, false);
//init firebase
firebaseAuth = FirebaseAuth.getInstance();
user = firebaseAuth.getCurrentUser();
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference("Users");
//init layout views
avatar = view.findViewById(R.id.avatar);
nameTxt = view.findViewById(R.id.nameTxt);
emailTxt = view.findViewById(R.id.emailTxt);
phoneTxt = view.findViewById(R.id.phoneTxt);
/* giriş yapan kullanıcıların bilgilerini email yada uid kullanarak çekmek zorundayız
Kullanıcı detaylarını email adreslerini kullanarak çekicez
orderbyChild query kullanarak giriş yapılan email ile email key ini eşleştirerek kullanıcı detaylarına ulaşılıyor
*/
Query query = databaseReference.orderByChild("email").equalTo(user.getEmail());
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
//gerekli veriler gelene kadar kontrol et
for (DataSnapshot ds: snapshot.getChildren()){
//verileri almak için
String name = ""+ ds.child("name").getValue();
String email = ""+ ds.child("email").getValue();
String phone = ""+ ds.child("phone").getValue();
String image = ""+ ds.child("image").getValue();
//set data
nameTxt.setText(name);
emailTxt.setText(email);
phoneTxt.setText(phone);
try {
// resim alınırsa ayarla
Picasso.get().load(image).into(avatar);
} catch (Exception e){
// resim alınırken herangi bir sıkıntı varsa varsayılan olarak ayarla
Picasso.get().load(R.drawable.add_photo_foreground).into(avatar);
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
return view;
}
}
and my fragment_profile.xml :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:background="#F1EDED"
tools:context=".ProfileFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="#2ECC71">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="horizontal"
android:layout_marginTop="100dp">
<ImageView
android:id="@+id/avatar"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/add_photo_foreground"
android:layout_marginStart="20dp"
android:background="#6AE493"
android:padding="5dp">
</ImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/nameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:textSize="25dp"
android:textColor="#FFFFFF"></TextView>
<TextView
android:id="@+id/emailTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:textColor="#FFFFFF"></TextView>
<TextView
android:id="@+id/phoneTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:textColor="#FFFFFF"></TextView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
I want to create a user profile page using firebase realtime database. The user details come from using email for current signed user. But my profile layout file does not work. How can I fix this problem? Whats wrong in my code?
My DasboardAvtivity.java -> For fragment transaction.
package com.gamze.pawsbook;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class DashboardActivity extends AppCompatActivity {
//FirebaseAuth
FirebaseAuth firebaseAuth;
//Actionbar
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
//ActionBar ve başlığı
actionBar = getSupportActionBar();
actionBar.setTitle("Profile");
//profileTxt = findViewById(R.id.profileTxt);
firebaseAuth = FirebaseAuth.getInstance();
//Bottom navigation
BottomNavigationView navigationView = findViewById(R.id.navigation);
navigationView.setOnNavigationItemSelectedListener(selectedListener);
//Home Fragment'ı boş default fragment olarak ayarlanması
actionBar.setTitle("Home"); //ActionBar başlığını değiştirme
HomeFragment homeFragment = new HomeFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content, homeFragment, "");
ft.commit();
}
private BottomNavigationView.OnNavigationItemSelectedListener selectedListener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
//itemlere tıklanma özelliği ekleme
switch (item.getItemId()){
case R.id.action_home:
//home fragment değişimi
actionBar.setTitle("Home"); //ActionBar başlığını değiştirme
HomeFragment homeFragment = new HomeFragment();
FragmentTransaction ftHome = getSupportFragmentManager().beginTransaction();
ftHome.replace(R.id.content, homeFragment, "");
ftHome.commit();
return true;
case R.id.action_map:
//map fragment değişimi
actionBar.setTitle("Map"); //ActionBar başlığını değiştirme
MapFragment mapFragment = new MapFragment();
FragmentTransaction ftMap = getSupportFragmentManager().beginTransaction();
ftMap.replace(R.id.content, mapFragment, "");
ftMap.commit();
return true;
case R.id.action_users:
//users fragment değişimi
actionBar.setTitle("Users"); //ActionBar başlığını değiştirme
UsersFragment usersFragment = new UsersFragment();
FragmentTransaction ftUsers = getSupportFragmentManager().beginTransaction();
ftUsers.replace(R.id.content, usersFragment, "");
ftUsers.commit();
return true;
case R.id.action_profile:
//profile fragment değişimi
actionBar.setTitle("Profile"); //ActionBar başlığını değiştirme
ProfileFragment profileFragment = new ProfileFragment();
FragmentTransaction ftProfile = getSupportFragmentManager().beginTransaction();
ftProfile.replace(R.id.content, profileFragment, "");
ftProfile.commit();
return true;
}
return false;
}
};
private void checkUserStatus() {
//mevcut kullanıcıyı al
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null){
//kullanıcı giriş yapmışsa burada kal
//giriş yapan kullanıcının email i
//profileTxt.setText(user.getEmail());
}
else{
//kullanıcı giriş yapmamışsa main activity'e git
Intent intent = new Intent(DashboardActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
@Override
protected void onStart() {
//uygulamanın başlangıcını konrtol et
checkUserStatus();
super.onStart();
}
//options menu dahil etme
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//menuyu dahil etme
getMenuInflater().inflate(R.menu.main_menu, menu);
return super.onCreateOptionsMenu(menu);
}
//menu itemlerine onClick özelliği aktifleştirme
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
//itemlerin id'lerini al
int id = item.getItemId();
if (id == R.id.action_logout){
//hesaptan çıkış yap
firebaseAuth.signOut();
checkUserStatus();
}
return super.onOptionsItemSelected(item);
}
}
activity_dashboard.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DashboardActivity">
//FrameLayout fragmentlerin üstüste gelebilmesi için daha kullanışlıdır
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp">
</FrameLayout>
//BottomNavigationBar
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:menu="@menu/bottombar_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>
答案1
得分: 0
这是从fragment_profile.xml
中显示的内容。
您的问题没有提供信息,无论您是否像上面那样获取了空视图,还是根本没有获取到任何视图。我将尝试根据两种假设进行回答。
- 空视图
- 根本没有视图
空视图
如果您获取到空视图,那么您必须在数据库响应中添加一些Logs
语句,检查数据库是否返回了某些值。
public class ProfileFragment extends Fragment {
//Log Statment
private static final String TAG = "ProfileFragment";
......
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
//检查直到必要的数据到达
for (DataSnapshot ds: snapshot.getChildren()){
//获取数据
String name = ""+ ds.child("name").getValue();
String email = ""+ ds.child("email").getValue();
String phone = ""+ ds.child("phone").getValue();
String image = ""+ ds.child("image").getValue();
//设置数据
nameTxt.setText(name);
emailTxt.setText(email);
phoneTxt.setText(phone);
Log.d(TAG, "onDataChange: \nName: "+name+" email: "+ email);
try {
//如果存在图像,则设置图像
Picasso.get().load(image).into(avatar);
} catch (Exception e){
//如果在获取图像时出现问题,则默认设置
Picasso.get().load(R.drawable.add_photo_foreground).into(avatar);
}
}
Log.d(TAG, "onDataChange: Data is empty");
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Log.d(TAG, "onCancelled: "+error);
}
}
}
.........
您还可以使用断点进行进一步调查。
根本没有视图
如果在ProfileFragment上视图没有改变,那么您必须检查您如何启动ProfileFragment。
getSupportFragmentManager().beginTransaction().replace(R.id.frgment_container, new ProfileFragment()).commit();
如果您使用导航组件,请确保您导航到正确的目标。
我还建议您在Profile Fragment下使用以下格式来构建代码:
public class ProfileFragment extends Fragment {
//Firebase auth
............
//Layout views
..............
public ProfileFragment() {
//必须有一个空的public构造函数
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//为此片段填充布局
View view = inflater.inflate(R.layout.fragment_profile, container, false);
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//初始化Firebase
..................
//初始化布局视图
.....................
/* 我们必须使用登录用户的信息来提取用户详细信息,使用电子邮件或UID
我们将使用电子邮件地址提取用户详细信息
通过使用orderbyChild查询,我们可以将登录电子邮件与电子邮件键匹配以获取用户详细信息
*/
Query query = databaseReference.orderByChild("email").equalTo(user.getEmail());
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
.............
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
.............
}
});
}
}
编辑(activity_dashboard.xml)
尝试以下布局文件以用于activity_dashboard.xml -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".DashboardActivity">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:menu="@menu/bottombar_menu"/>
</RelativeLayout>
我使用了?attr/actionBarSize
,这是Android的标准操作栏大小。
祝您编码愉快!
英文:
This is what is showing from fragment_profile.xml
.
Your question doesn't give information whether you are getting an empty view like above or you are not getting any view. I will try to answer on two ansumption.
- Empty View
- No View at all
Empty View
If you are getting empty view then you must put some Logs
statement in your database responce, check if that database is returning some value.
public class ProfileFragment extends Fragment {
//Log Statment
private static final String TAG = "ProfileFragment";
......
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
//gerekli veriler gelene kadar kontrol et
for (DataSnapshot ds: snapshot.getChildren()){
//verileri almak için
String name = ""+ ds.child("name").getValue();
String email = ""+ ds.child("email").getValue();
String phone = ""+ ds.child("phone").getValue();
String image = ""+ ds.child("image").getValue();
//set data
nameTxt.setText(name);
emailTxt.setText(email);
phoneTxt.setText(phone);
Log.d(TAG, "onDataChange: \nName: "+name+" email: "+ email);
try {
// resim alınırsa ayarla
Picasso.get().load(image).into(avatar);
} catch (Exception e){
// resim alınırken herangi bir sıkıntı varsa varsayılan olarak ayarla
Picasso.get().load(R.drawable.add_photo_foreground).into(avatar);
}
}
Log.d(TAG, "onDataChange: Data is empty");
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Log.d(TAG, "onCancelled: "+error);
}
}
}
.........
You can use breakpoints as well to further investigation.
No View at all
If view is not changing on ProileFragment then you must check how you are starting ProfileFragment.
getSupportFragmentManager().beginTransaction().replace(R.id.frgment_container, new ProfileFragment()).commit();
If you are using Navigation Component then make sure you are navigating to correct destination.
I will also suggest you to strcture the code in following format under Profile Fragment -
public class ProfileFragment extends Fragment {
//firebase auth
............
//layout views
..............
public ProfileFragment() {
//boş public constructor gerekli
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_profile, container, false);
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//init firebase
.................
//init layout views
.......................
/* giriş yapan kullanıcıların bilgilerini email yada uid kullanarak çekmek zorundayız
Kullanıcı detaylarını email adreslerini kullanarak çekicez
orderbyChild query kullanarak giriş yapılan email ile email key ini eşleştirerek kullanıcı detaylarına ulaşılıyor
*/
Query query = databaseReference.orderByChild("email").equalTo(user.getEmail());
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
.................
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
...............
}
});
}
}
Edit (activity_dashboard.xml)
Try following layout file for activity_dashboard.xml -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".DashboardActivity">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:menu="@menu/bottombar_menu"/>
</RelativeLayout>
I am using ?attr/actionBarSize
, which is the standard action bar size for android.
Happy Coding !
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论