我有一个项目,要查询Firebase实时数据库中的两个数据。事情是,我只想在查询中得到一个结果。 例如SQL
SELECT * JOBS WHERE PHONE EQUAL TO PHONE
我已经明白了。我想要的就是结合查询电话和查询日期的位置。我正在尝试此操作,但是应用程序崩溃了。对不起,我的英语不好。我希望你们能理解我的意思。
public class CheckOrder extends AppCompatActivity {
private static final String TAG = "Image";
public RecyclerView recyclerView;
public RecyclerView.LayoutManager layoutManager;
FirebaseRecyclerAdapter<BothJobs, JobViewHolder> adapter;
FirebaseRecyclerAdapter<BothJobs, JobViewHolder> checkadapter;
private FirebaseDatabase database;
private DatabaseReference jobs;
MaterialSpinner spinner;
String phone;
String flightDate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_order);
database = FirebaseDatabase.getInstance();
jobs = database.getReference("Jobs");
recyclerView = findViewById(R.id.listCheckOrders);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
phone = Common.currentUser.getPhone();
flightDate = Common.currentUser.getFlightDate();
if (flightDate != null)
loadOrders();
}
private void loadOrders() {
final Query jobsProject = jobs.orderByChild("phone").equalTo(phone);
jobsProject.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot movieSnapshot : dataSnapshot.getChildren()) {
BothJobs jobsCarrier = dataSnapshot.getValue(BothJobs.class);
if (jobsCarrier.getTimestamp().equals(flightDate)) {
adapter = new FirebaseRecyclerAdapter<BothJobs, JobViewHolder>(
BothJobs.class,
R.layout.check_order_layout,
JobViewHolder.class,
jobsProject
) {
@Override
protected void populateViewHolder(JobViewHolder viewHolder, final BothJobs model, int position) {
viewHolder.tvId.setText("ID : " + adapter.getRef(position).getKey());
viewHolder.tvName.setText("Carrier Name : " + model.getName());
viewHolder.tvStatus.setText("Status : " + Common.convertCodeToStatus(model.getStatus()));
viewHolder.tvAirport.setText("Airport : " + model.getAirport());
viewHolder.tvAirlines.setText("Airlines : " + model.getAirlines());
viewHolder.tvLuggage.setText("Free Space Luggage : " + model.getSpace());
viewHolder.tvLocation.setText("Location Want To Go : " + model.getLocation());
viewHolder.tvPhone.setText("Carrier Contact : " + model.getPhone());
RequestOptions placeholderRequest = new RequestOptions();
placeholderRequest.placeholder(R.drawable.profile);
Glide.with(getBaseContext()).setDefaultRequestOptions(placeholderRequest).load(model.getImage()).into(viewHolder.imageCarrier);
RequestOptions placeholderRequest2 = new RequestOptions();
placeholderRequest2.placeholder(R.drawable.wedee);
Glide.with(getBaseContext()).setDefaultRequestOptions(placeholderRequest2).load(model.getFlightDetail()).into(viewHolder.flightDetail);
viewHolder.btn_checkJob.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Intent to ChooseJob
Toast.makeText(CheckOrder.this, "Job" + model.getId(), Toast.LENGTH_SHORT).show();
}
});
}
};
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter);
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
我正在尝试将时间戳等于航班日期与phone等于phone匹配。但是什么也没出现,我暂时没有崩溃。 this image from "Jobs" ref this image from "User" ref