【发布时间】:2019-11-07 14:06:13
【问题描述】:
我已将我的 android 应用程序与 firebase 实时数据库连接起来。它通过一个活动成功地从数据库和项目中检索数据,该活动是显示 CardView 布局的 RecyclerView。现在,当我选择一个特定的 CARD 时,应该会弹出一个对话框,仅在对话框布局中显示该特定 firebase 节点的所有数据。
我需要获取该选定 CARD 的 pushID(作为“selectedKey”变量)并调用对话框,该对话框通过使用该“KEY”字符串再次从数据库中检索来显示来自 firebase 的数据... 或者有没有其他简单的方法...?
我还说明了我想做的事情。
connected firebase database showing the node
app activity and dialog layout
<holder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position) {
selectedArticle = model;
selectedKey = getSnapshots().getSnapshot(position).getKey();
Log.d("Key item", ""+selectedKey);
showArticle.setContentView(R.layout.show_article_dialog);
show_article_title.setText(model.getTitle());
show_article_tag1.setText(model.getTag1());
show_article_tag2.setText(model.getTag2());
show_article_tag3.setText(model.getTag3());
show_article_content.setText(model.getContent());
articleBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showArticle.dismiss();
}
});
showArticle.show();>
【问题讨论】:
-
到目前为止你在代码中尝试过什么?
-
可以看到上面的代码——@AlexMamo
-
getSnapshots().getSnapshot(position).getKey()是否返回了正确的密钥? -
.getKey() 在这里返回正确的密钥;
-
实际上我的问题是,如何通过单击其中一张卡来显示弹出对话框,然后使用 KEY 从 firebase 获取数据?调用 'dialog.setContentView.(LAYOUT)' 在这里不起作用! - @AlexMamo
标签: android firebase android-recyclerview android-cardview android-dialog