应用程序未从Firebase数据库检索任何数据。应用程序运行良好,但在应用程序内不显示任何内容,只显示空白。这里是我的代码从Firebase数据库中检索时未显示数据
public class profilemain extends AppCompatActivity {
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private Firebase url;
private ListView listview;
ArrayList<String> arrayList=new ArrayList<>();
ArrayAdapter<String> arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profilemain);
listview=(ListView) findViewById(R.id.listview);
Firebase.setAndroidContext(this);
url=new Firebase("https://-------.firebaseio.com/users");
arrayAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arrayList);
listview.setAdapter(arrayAdapter);
url.addChildEventListener(new com.firebase.client.ChildEventListener() {
@Override
public void onChildAdded(com.firebase.client.DataSnapshot dataSnapshot, String s) {
String value=dataSnapshot.getValue(String.class);
arrayList.add(value);
arrayAdapter.notifyDataSetChanged();
}
// .. Other Overriden functions
});
mAuth=FirebaseAuth.getInstance();
mAuthListener =new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser()==null){
startActivity(new Intent(profilemain.this,MainActivity.class));
}
}
};
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
}
这里是我的xml文件如下。该应用程序运行良好,但没有显示数据。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.food.sheenishere.stark.profilemain">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:id="@+id/listview"
style="@style/Widget.AppCompat.ListView"
android:layout_width="wrap_content"
android:layout_height="337dp" />
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/navigation" />
</LinearLayout>
下面是我的Firebase数据库的模式。
请特别注意您的问题。这个问题正在寻求调试帮助。 –
我具体说明未检索到数据 –
请在Firebase中添加数据的虚拟快照。我们需要在Firebase中查看您的数据结构。 –