我是Android编程的新手。我想创建按名称排序并基于类别进行过滤的列表。但是当我这样做时,列表按类别进行了过滤,但没有按名称排序,也没有任何错误。有没有解决这个问题而无需更改数据库结构?
这是我的代码。
mAgrowisataDatabase = FirebaseDatabase.getInstance().getReference().child("Places");
FirebaseRecyclerAdapter<Places, PlacesViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Places, PlacesViewHolder>(
Places.class,
R.layout.place_single_layout,
PlacesViewHolder.class,
mAgrowisataDatabase.orderByChild("category").equalTo("Nature")
) {
@Override
protected void populateViewHolder(final PlacesViewHolder viewHolder, final Places model, final int position) {
final String mKey = getRef(position).getKey();
mAgrowisataDatabase.child(mKey).orderByChild("name").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()){
viewHolder.setName(model.getName());
viewHolder.setPrice(model.getPrice());
viewHolder.setThumb_image(model.getThumb_image(), getApplicationContext());
final String placeUid = getRef(position).getKey();
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent detailIntent = new Intent(AgrowisataActivity.this, DetailActivity.class);
detailIntent.putExtra("placeUid", placeUid);
startActivity(detailIntent);
detailIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
};
mAgrowisataList.setAdapter(firebaseRecyclerAdapter);
数据库表的图片,谢谢。