【发布时间】:2020-08-25 08:48:21
【问题描述】:
我正在制作应用程序,我使用 firestore 作为数据库。我制作了一个由电影(只是名称)组成的 listView。当我单击其中一个活动时,我想在另一个活动中显示详细信息。我为此做了一些事情,但我刚刚得到了我添加的最后一部电影。当我单击另一个时,结果是我添加的最后一部电影。所有电影细节都是一样的。我无法解决这个问题。我该如何解决?
这就是我制作 listView 部分的方式
public class Izlediklerim extends AppCompatActivity {
private FirebaseAuth firebaseAuth;
private FirebaseFirestore firebaseFirestore;
ArrayList<String> adArray;
ListView listView;
ArrayAdapter arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_izlediklerim);
firebaseFirestore=FirebaseFirestore.getInstance();
adArray=new ArrayList<>();
listView=findViewById(R.id.listView);
arrayAdapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,adArray);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent=new Intent(Izlediklerim.this,FilmiGoster.class);
startActivity(intent);
}
});
filmleriAl();
}
public void filmleriAl(){
CollectionReference collectionReference = firebaseFirestore.collection("Filmler");
collectionReference.orderBy("filmtarih").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
if (e != null) {
Toast.makeText(Izlediklerim.this, e.getLocalizedMessage().toString(), Toast.LENGTH_LONG).show();
}
if (queryDocumentSnapshots != null) {
for (DocumentSnapshot snapshot : queryDocumentSnapshots.getDocuments()) {
Map<String, Object> data = snapshot.getData();
String name = (String) data.get("filmadi");
adArray.add(name);
arrayAdapter.notifyDataSetChanged();
}
}
}
});
}
}
这是细节部分
public class FilmiGoster extends AppCompatActivity {
ImageView fr;
TextView fa,ft,fh;
private FirebaseAuth firebaseAuth;
private FirebaseFirestore firebaseFirestore;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_filmi_goster);
fr=findViewById(R.id.fr);
fa=findViewById(R.id.fa);
ft=findViewById(R.id.ft);
fh=findViewById(R.id.fh);
firebaseFirestore=FirebaseFirestore.getInstance();
firebaseAuth=FirebaseAuth.getInstance();
CollectionReference collectionReference = firebaseFirestore.collection("Filmler");
collectionReference.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
if (e != null) {
Toast.makeText(FilmiGoster.this,e.getLocalizedMessage().toString(),Toast.LENGTH_LONG).show();
}
if (queryDocumentSnapshots != null) {
for (DocumentSnapshot snapshot : queryDocumentSnapshots.getDocuments()) {
Map<String, Object> data = snapshot.getData();
String hakkinda = (String) data.get("filmdusunce");
String ad = (String) data.get("filmadi");
String downloadUrl = (String) data.get("downloadurl");
String zaman = (String) data.get("filmtarih");
fa.setText(ad);
Picasso.get().load(downloadUrl).into(fr);
fh.setText(hakkinda);
ft.setText(zaman);
}
}
}
});
}
}
【问题讨论】:
标签: java android firebase android-studio google-cloud-firestore