我想向Firebase数据库列表视图添加新活动,但是我没有这样做。我有一个名为“ Books(Kitaplar)”的数据库。当用户查看列表中的书籍时,请转到他们想要的书籍的新页面。非常感谢... 注意:Listesayfahali表示Firebase数据库的listview进入新页面。
package com.eraykalelioglu.ki_ta;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;
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.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class Listesayfahali extends AppCompatActivity {
DatabaseReference databaseKitaplar;
ListView listViewKitaplars;
List<Kitaplar> kitaplarList;
TextView textViewName;
TextView textViewYazar;
TextView textViewGenre;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listesayfahali);
databaseKitaplar = FirebaseDatabase.getInstance().getReference();
textViewName = (TextView) findViewById(R.id.textViewName);
textViewYazar = (TextView) findViewById(R.id.textViewYazar);
textViewGenre = (TextView) findViewById(R.id.textViewGenre);
listViewKitaplars = (ListView) findViewById(R.id.listViewKitaplars);
kitaplarList = new ArrayList<>();
}
@Override
protected void onStart() {
super.onStart();
databaseKitaplar.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
kitaplarList.clear();
for (DataSnapshot kitaplarSnapshot : dataSnapshot.getChildren()) {
Kitaplar kitaplar = kitaplarSnapshot.getValue(Kitaplar.class);
kitaplarList.add(kitaplar);
}
BookList adapter = new BookList(Listesayfahali.this, kitaplarList);
listViewKitaplars.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}