我试图按照常规方法从我的firebase实时数据库中获取一些数据,但无法弄清楚问题出在哪里。
以下Toast语句不返回任何内容,以某种方式populateViewHolder无法正常工作!
无法确定问题出在哪里。有人可以指出吗?
任何事情都将不胜感激!该代码附在下面-
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);
}
}
}
我用吸气剂塞特...
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;
}
}
和数据库
答案 0 :(得分:0)
private void SearchDoc(String searchBoxInput1) {
Toast.makeText(this, "searching..", Toast.LENGTH_LONG).show();
Query searchdoctorquery = allDocdatabaseref.orderByChild("name").startAt(searchBoxInput1).endAt(searchBoxInput1 + "\uf8ff");
firebaseRecyclerAdapter
= new FirebaseRecyclerAdapter<FindDoctors, FindDoctorsViewHolder>(
FindDoctors.class,
R.layout.all_userdoc_display_layout,
FindDoctorsViewHolder.class,
searchdoctorquery
) {
@Override
protected void populateViewHolder(FindDoctorsViewHolder viewHolder, FindDoctors model, int position) {
/// Toast.makeText(getApplicationContext(),model.getName().toString(), Toast.LENGTH_LONG).show();
viewHolder.setbmdc(model.getbmdc());
viewHolder.setName(model.getName());
}
};
SearchResult_doc.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.startListening();
}