gpt4 book ai didi

java - 我如何检索 child (名称和列表图像)

转载 作者:行者123 更新时间:2023-12-02 11:03:29 28 4
gpt4 key购买 nike

我正在尝试从基本子项的列表子项中检索名称和list_image。 在这里,我从上一张卡中获取一个 ID 来检索内部信息,但我无法检索数据,无法找到实际问题。

enter image description here

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 图像。

最佳答案

问题出在这个 fragment 中:

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();

关于java - 我如何检索 child (名称和列表图像),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51154521/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com