I am trying to create an app that will allow users to rent a car nearest to them. I want to build a cardView with a textView and imageView once i find the nearest car, I created the method buildCardView to do that. My problem is that the cardView is not getting created when its called. buildCardView works fine when I call it directly, but not when called inside of the Geoquery onKeyEntered method. I debugged the code and the method buildCardView is getting called inside of on onKeyEntered but the cardView is not visible. Below is the code for that calls the firebase method.
FindCar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
findClosestCars();
}
});
Below is the firebase method that calls buildCardView
private void findClosestCars() {
if (ActivityCompat.checkSelfPermission(RentersMenuPageActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
// turnOnLocationUpdates();
//fusedLocationClient.requestLocationUpdates(mLocationRequest, locationCallback, Looper.myLooper());
databaseReference = FirebaseDatabase.getInstance().getReference("Users").child("Lenders");
GeoFire geoFire = new GeoFire(databaseReference);
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(latitude, longitude), radius);
geoQuery.removeAllListeners();
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
//
// Toast.makeText(RentersMenuPageActivity.this, "You Found a Lender",Toast.LENGTH_LONG);
// Toast.LENGTH_LONG).show();
//showPictureAndPrice();
if (!driverFound) {
driverFound = true;
driverFoundID = key;
closestLender = FirebaseDatabase.getInstance().getReference("Users").child("Lenders").child(driverFoundID);
String [] lenderLocations;
buildCardView();
}
radius++;
}
Below is buildCardView that inflates a smaller view inside the main one (works when called directly but not from onkeyentered)
private void buildCardView(){
Toast.makeText(RentersMenuPageActivity.this, "You Found a Lender",Toast.LENGTH_LONG).show();
LayoutInflater mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View view =getLayoutInflater().inflate(R.layout.card,null);
// CardView cardView = view.findViewById(R.id.cardView);
Button rentCarButton = view.findViewById(R.id.rentCarButton);
TextView price= view.findViewById(R.id.price);
TextView makeandmodel = view.findViewById(R.id.makeandmodel);
ImageView imageView =view.findViewById(R.id.imageViewScroll);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
linearLayout.addView(view);
}
from My method does not work inside of onKeyEntered
No comments:
Post a Comment