2

I have tried several times but my recyclerview stays empty every time i run my app but there are no errors.cant find what is the problem please help.

I think the problem is in the LoadData()action but i cant tell .

my main java class with the Viewholder

public class SearchCar extends AppCompatActivity {
    EditText mSearch;
    ImageButton mSearchBtn;
    RecyclerView mRecycler;
    FirebaseRecyclerOptions<Cars>options;
    FirebaseRecyclerAdapter<Cars,ViewHolder>adapter;
    DatabaseReference mUserDatabase;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_car);


        mUserDatabase = FirebaseDatabase.getInstance().getReference().child("Cars");
        mSearch = findViewById(R.id.etSearch);
        mSearchBtn = findViewById(R.id.btnSearch);
        mRecycler = findViewById(R.id.LRecycler);
        mRecycler.setHasFixedSize(true);
        mRecycler.setLayoutManager(new LinearLayoutManager(getApplicationContext()));

        LoadData();



    private void LoadData() {
        Toast.makeText(this, "started Search", Toast.LENGTH_SHORT).show();
        options = new FirebaseRecyclerOptions.Builder<Cars>().setQuery(mUserDatabase,Cars.class).build();
        adapter = new FirebaseRecyclerAdapter<Cars, ViewHolder>(options) {
            @Override
            protected void onBindViewHolder(@NonNull ViewHolder holder,final int position, @NonNull Cars model) {
                holder.CarBrand.setText(model.getAddBName());
                holder.CarModle.setText(model.getAddWName());
                holder.CarPrice.setText(model.getPrice());
                holder.CarYear.setText(model.getAddYearOfPublishing());
                Picasso.get().load(model.getImageUrl()).into(holder.CarsImage);

            }

            @NonNull
            @Override
            public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

                View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_layout,parent,false);
                return new ViewHolder(v);
            }
        };
        adapter.startListening();
        mRecycler.setAdapter(adapter);



    }
 public static class ViewHolder extends RecyclerView.ViewHolder {

        EditText CarModle,CarBrand,CarPrice,CarYear;
        ImageView CarsImage;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            CarModle = itemView.findViewById(R.id.tvCarmod);
            CarBrand = itemView.findViewById(R.id.tvBrand);
            CarPrice = itemView.findViewById(R.id.TvPrice);
            CarYear = itemView.findViewById(R.id.tvYear);
            CarsImage = itemView.findViewById(R.id.ivPic);

        }




my dependencies

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:19.3.1'
    implementation 'com.google.firebase:firebase-database:19.3.0'
    implementation 'com.google.firebase:firebase-storage:19.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.firebaseui:firebase-ui-database:6.2.1'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}

my model class


public class Cars {
    public String addBName,imageUrl,price,addYearOfPublishing,addWName;
    public Cars(){

    }

    public String getAddBName() {
        return addBName;
    }

    public String getAddWName() {
        return addWName;
    }

    public void setAddWName(String addWName) {
        this.addWName = addWName;
    }

    public void setAddBName(String addBName) {
        this.addBName = addBName;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getAddYearOfPublishing() {
        return addYearOfPublishing;
    }

    public void setAddYearOfPublishing(String addYearOfPublishing) {
        this.addYearOfPublishing = addYearOfPublishing;
    }

    public Cars(String addBName, String imageUrl, String price, String addYearOfPublishing,String addWName) {
        this.addBName = addBName;
        this.imageUrl = imageUrl;
        this.price = price;
        this.addYearOfPublishing = addYearOfPublishing;
        this.addWName = addWName;
    }
}


My firebase database:

enter image description here

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
  • Hi! According to specification provided, I believe you are missing something like firebaseRecyclerAdapter.startListening(); Please, check if you have added everything you need (I believe you can get an answer in this question : https://stackoverflow.com/questions/54616893/retrieving-data-using-firebaserecycleroptions) – kboskin Jun 13 '20 at 16:23

0 Answers0