FirebaseRecyclerAdapter 添加 hasChild() 方法?
FirebaseRecyclerAdapter add a hasChild() method?
这是我的数据库:
Database:{
X:{
JK-KDUKSIDKSIIJDSL1:{
text:"hello",
name:"Donald J. Drunk"
}
JK-KDadDFDDIJDSL1:{
name:"Killery Hlinton"
}
}
}
而且我想过滤我的 FirebaseRecyclerAdapter
,以便只添加到我的 RecyclerView
包含键 text
的数据。这怎么可能?我怎样才能添加它?当前代码:
mAdapter = new FirebaseRecyclerAdapter<Campaign, CampaignHolder>(Campaign.class, R.layout.recyclerview_template, CampaignHolder.class, ref) {
@Override
public void populateViewHolder(final CampaignHolder viewHolder, final Campaign campaign, final int position) {
findViewById(R.id.progress_bar).setVisibility(View.INVISIBLE);
MainActivity.this.holder = viewHolder;
viewHolder.setTitle(campaign.title);
//... Other "set" methods
}
}
您可以尝试覆盖 FirebaseRecyclerAdapter
中的 onBindViewHolder
方法。像这样:
mAdapter = new FirebaseRecyclerAdapter<Campaign, CampaignHolder>(Campaign.class, R.layout.recyclerview_template, CampaignHolder.class, ref) {
@Override
public void onBindViewHolder(CampaignHolder viewHolder, int position) {
Campaign model = getItem(position);
if(model.getText() != null){
populateViewHolder(viewHolder, model, position);
}
}
@Override
public void populateViewHolder(final CampaignHolder viewHolder, final Campaign campaign, final int position) {
findViewById(R.id.progress_bar).setVisibility(View.INVISIBLE);
MainActivity.this.holder = viewHolder;
viewHolder.setTitle(campaign.title);
//... Other "set" methods
}
};
使用这种方法,您仍然可以在查询位置提取所有数据,但不会显示没有文本属性的条目。如果这不令人满意,并且您想最大程度地减少每次查询下载的数据量,那么我看到的唯一其他选项更接近上面评论中提到的内容 - 这意味着您需要创建一个单独的位置,只存储那些条目有一个文本值。
这是我的数据库:
Database:{
X:{
JK-KDUKSIDKSIIJDSL1:{
text:"hello",
name:"Donald J. Drunk"
}
JK-KDadDFDDIJDSL1:{
name:"Killery Hlinton"
}
}
}
而且我想过滤我的 FirebaseRecyclerAdapter
,以便只添加到我的 RecyclerView
包含键 text
的数据。这怎么可能?我怎样才能添加它?当前代码:
mAdapter = new FirebaseRecyclerAdapter<Campaign, CampaignHolder>(Campaign.class, R.layout.recyclerview_template, CampaignHolder.class, ref) {
@Override
public void populateViewHolder(final CampaignHolder viewHolder, final Campaign campaign, final int position) {
findViewById(R.id.progress_bar).setVisibility(View.INVISIBLE);
MainActivity.this.holder = viewHolder;
viewHolder.setTitle(campaign.title);
//... Other "set" methods
}
}
您可以尝试覆盖 FirebaseRecyclerAdapter
中的 onBindViewHolder
方法。像这样:
mAdapter = new FirebaseRecyclerAdapter<Campaign, CampaignHolder>(Campaign.class, R.layout.recyclerview_template, CampaignHolder.class, ref) {
@Override
public void onBindViewHolder(CampaignHolder viewHolder, int position) {
Campaign model = getItem(position);
if(model.getText() != null){
populateViewHolder(viewHolder, model, position);
}
}
@Override
public void populateViewHolder(final CampaignHolder viewHolder, final Campaign campaign, final int position) {
findViewById(R.id.progress_bar).setVisibility(View.INVISIBLE);
MainActivity.this.holder = viewHolder;
viewHolder.setTitle(campaign.title);
//... Other "set" methods
}
};
使用这种方法,您仍然可以在查询位置提取所有数据,但不会显示没有文本属性的条目。如果这不令人满意,并且您想最大程度地减少每次查询下载的数据量,那么我看到的唯一其他选项更接近上面评论中提到的内容 - 这意味着您需要创建一个单独的位置,只存储那些条目有一个文本值。