java - 我如何检索孩子(姓名和列表图像)
问题描述
我正在尝试从 Basic 子项的 List 子项中检索 name 和 list_image。在这里,我从以前的卡中提取了一个 id 来检索内部信息,但我无法检索数据,找不到实际问题。
public class fund_list extends AppCompatActivity {
private DatabaseReference listref_basic, listref_advanced;
String FundId = "";
private static final String TAG = "MyActivity";
RecyclerView list_recyclerview;
RecyclerView.LayoutManager layoutManager;
FirebaseRecyclerAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fund_list);
listref_basic = FirebaseDatabase.getInstance().getReference().child("Basic");
//listref_advanced = FirebaseDatabase.getInstance().getReference().child("Advanced");
list_recyclerview = (RecyclerView) findViewById(R.id.list_RecyclerView);
list_recyclerview.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
list_recyclerview.setLayoutManager(layoutManager);
if (getIntent() != null) {
Log.i(TAG, "inside 1st if statement ");
FundId = getIntent().getStringExtra("FundId");
}
if (!FundId.isEmpty()) {
Log.i(TAG, "inside 2nd if statement ");
getList(FundId, listref_basic);
}
}
private void getList(String fundId, DatabaseReference DR) {
DR.child(fundId).child("List");
Log.i(TAG, "inside getlist method ");
FirebaseRecyclerOptions<List> options =
new FirebaseRecyclerOptions.Builder<List>()
.setQuery(DR, List.class)
.build();
Log.i(TAG, "after options ");
adapter = new FirebaseRecyclerAdapter<List, List_holder>(options) {
@Override
protected void onBindViewHolder(@NonNull List_holder holder, int position, @NonNull List model) {
holder.setName(model.getName());
holder.setList_image(getApplicationContext(), model.getList_image());
Log.i(TAG, "inside onbind");
}
@NonNull
@Override
public List_holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_card, parent, false);
return new List_holder(view);
}
};
list_recyclerview.setAdapter(adapter);
adapter.startListening();
adapter.notifyDataSetChanged();
Log.i(TAG, "after set adapter ");
}
这是我一直在尝试检索的 firebase 的图像。
解决方案
问题出在这个片段中:
DR.child(fundId).child("List");
Log.i(TAG, "inside getlist method ");
FirebaseRecyclerOptions<List> options =
new FirebaseRecyclerOptions.Builder<List>()
.setQuery(DR, List.class)
.build();
你没有存储DR.child(fundId).child("List")
任何地方的结果,所以当你传入DR
它时setQuery
只是指向Basic
.
解决方案是存储对用户列表的引用并将其传递到您的FirebaseRecyclerOptions
:
DatabaseReference usersListReference = DR.child(fundId).child("List");
Log.i(TAG, "inside getlist method ");
FirebaseRecyclerOptions<List> options =
new FirebaseRecyclerOptions.Builder<List>()
.setQuery(usersListReference, List.class)
.build();
推荐阅读
- javascript - 将整个页面作为 iframe 嵌入子目录中(iframe 中的相对路径不起作用)
- protractor - 报告/显示 Protractor Cucumber html 中的断言失败报告为步骤失败
- javascript - ngb 分页 [(page)] 角度中的属性不起作用
- python - 在 Python 中从 .dat 文件数据帧中读取
- flutter - Flutter web - 水平的singlechildscrollview不能用鼠标滚轮滚动
- flutter - setState() 或 markNeedsBuild() 在动态字段中的 onChange 函数期间在构建期间调用
- javascript - 如何解决我的 json-server 的 ENOENT 错误?
- python - 来自字符串的带有 getattr 和 args/kwargs 的 Python 调用函数
- python - pcap 到 csv 仅 104asdu 协议,具有字段 noframe、lenframe、apdulen、rx、tx、type、typeid、causetx、ioa、numix、oa
- sql - 跳过 Id 列表的第一个插入记录的耗时查询