Изображение базы данных коллекции адресов
Изображение базы данных списка документов
Я хочу отобразить отсортированные данные в соответствии с моим списком в RecyclerView (IЯ могу получить данные, но они не отсортированы согласно списку моих коллекций). Или я отсортировал список адресов коллекции в Firestore и хочу получить отсортированные данные из списка документов Firestore. Пожалуйста, найдите приложенное изображение базы данных Firestore и код Java для подробностей.
public class ViewSelectedActivity extends AppCompatActivity {
private RecyclerView addressRecyclerView;
private FirebaseFirestore fireStoreDb = FirebaseFirestore.getInstance();
public static AddressAdapter addressActivityAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_selected);
addressRecyclerView = findViewById(R.id.address_recycler_view);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
addressRecyclerView.setLayoutManager(layoutManager);
final List<AddressModel> addressModelList1 = new ArrayList<>();
addressModelList1.clear();
addressModelList1.add(new AddressModel("Ravi11111", "Fist1", "City1", "111111", "111"));//Manual address list is working fine.
addressModelList1.add(new AddressModel("222", "Fist1", "222", "111111", "111"));
addressModelList1.add(new AddressModel("Ravi11111", "333", "City33", "111111", "111"));
fireStoreDb.collection("Selected_user").document("Address").get()
.addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull final Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
for (long x = 1; x <= (long) task.getResult().get("Address_Size"); x++) {
String addressId = task.getResult().getString("Address_0" + x);
fireStoreDb.collection("AddressCollection").document(addressId).get()
.addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task1) {
if (task1.isSuccessful()) {
addressModelList1
.add(new AddressModel(task1.getResult().getString("Full_Name")
, task1.getResult().getString("House_No")
, task1.getResult().getString("City")
, task1.getResult().getString("Pincode")
, task1.getResult().getString("Mobile_No")));
addressActivityAdapter.notifyDataSetChanged();
}
}
});
}
}
}
});
addressActivityAdapter = new AddressAdapter(addressModelList1);
addressRecyclerView.setAdapter(addressActivityAdapter);
//address1adapter.notifyDataSetChanged();
}
}
public class AddressModel {
private String name;
private String house;
private String city;
private String pincode;
private String mobile;
public AddressModel(String name, String house, String city, String pincode, String mobile) {
this.name = name;
this.house = house;
this.city = city;
this.pincode = pincode;
this.mobile = mobile;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getHouse() {
return house;
}
public void setHouse(String house) {
this.house = house;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPincode() {
return pincode;
}
public void setPincode(String pincode) {
this.pincode = pincode;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
}
public class AddressAdapter extends RecyclerView.Adapter<AddressAdapter.AddressViewHolder> {
private List<AddressModel> addressModelList;
public AddressAdapter(List<AddressModel> addressModelList) {
this.addressModelList = addressModelList;
}
@NonNull
@Override
public AddressViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.address_item_layout, viewGroup, false);
return new AddressViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull AddressViewHolder viewHolder, int position) {
String b_name = addressModelList.get(position).getName();
String b_house = addressModelList.get(position).getHouse();
String b_city = addressModelList.get(position).getCity();
String b_pincode = addressModelList.get(position).getPincode();
String b_mobile = addressModelList.get(position).getMobile();
viewHolder.setData(b_name,b_house,b_city,b_pincode, b_mobile);
}
@Override
public int getItemCount() {
return addressModelList.size();
}
class AddressViewHolder extends RecyclerView.ViewHolder {
private TextView aname;
private TextView ahouse;
private TextView acity;
private TextView apincode;
private TextView amobile;
public AddressViewHolder(@NonNull View itemView) {
super(itemView);
aname = itemView.findViewById(R.id.view_full_name);
ahouse = itemView.findViewById(R.id.view_house_no);
acity = itemView.findViewById(R.id.view_city);
apincode = itemView.findViewById(R.id.view_pincode);
amobile = itemView.findViewById(R.id.view_mobile_no);
}
private void setData(String nameText, String houseText, String cityText, String pinText, String mobileText) {
aname.setText(nameText);
ahouse.setText(houseText);
acity.setText(cityText);
apincode.setText(pinText);
amobile.setText(mobileText);
}
}
}