I was trying to get some data from my Firebase realtime-database as followed generally, but couldn't figure out where the problem is.
The following Toast statement returns with nothing, somehow that populateViewHolder is not working! Where might the problem be?
The code is here:
package com.example.abed.smit;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
public class FindDocActivity extends AppCompatActivity {
private ImageView searchbtn;
private EditText searchInput;
private RecyclerView searchResulist;
private DatabaseReference allusersDatabaseref;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_doc);
searchResulist= findViewById(R.id.search_result_list1);
searchResulist.setHasFixedSize(true);
searchResulist.setLayoutManager(new LinearLayoutManager(this));
searchbtn=(ImageView)findViewById(R.id.search_people_btn1);
searchInput=(EditText)findViewById(R.id.Search_box_input1);
allusersDatabaseref= FirebaseDatabase.getInstance().getReference().child("BMDC").child("01");
searchbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String searchBoxInput = searchInput.getText().toString();
SearchPropleAnddonnor(searchBoxInput);
}
});
}
private void SearchPropleAnddonnor(String searchBoxInput) {
Toast.makeText(this,"Searching..",Toast.LENGTH_LONG).show();
Query searchpeopleBloodquery=allusersDatabaseref.orderByChild("ID")
.startAt(searchBoxInput).endAt(searchBoxInput+"\uf8ff");
FirebaseRecyclerAdapter<FindDoctors,FindBloodViewHolder>firebaseRecyclerAdapter=
new FirebaseRecyclerAdapter<FindDoctors, FindBloodViewHolder>
(
FindDoctors.class,
R.layout.all_userdoc_display_layout,
FindBloodViewHolder.class,
searchpeopleBloodquery
) {
@Override
protected void populateViewHolder(FindBloodViewHolder viewHolder, FindDoctors model, int position) {
viewHolder.setName(model.getName());
viewHolder.setId(model.getId());
}
};
searchResulist.setAdapter(firebaseRecyclerAdapter);
}
public static class FindBloodViewHolder extends RecyclerView.ViewHolder{
View mView;
public FindBloodViewHolder(View itemView ) {
super(itemView);
mView=itemView;
}
public void setName(String name){
TextView myname=(TextView)mView.findViewById(R.id.all_user_profile_name1);
myname.setText(name);
}
public void setId(String id){
TextView mystatus=(TextView)mView.findViewById(R.id.all_user_profile_status1);
mystatus.setText(id);
}
}
}
I used getter setter:
package com.example.abed.smit;
public class FindDoctors {
public String id , name;
public FindDoctors(String id, String name) {
this.id = id;
this.name = name;
}
public FindDoctors() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
and database