Я пытался получить некоторые данные из своей базы данных в реальном времени firebase, как обычно, но не мог понять, где в коде меня преследовала проблема. Не могу понять, в чем проблема. Кто-нибудь может указать на это? Все будет оценено! Код прикреплен ниже - `package com.example.abed.smit;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
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 FindMedicineActivity extends AppCompatActivity {
private Button SearchButton_medicine;
private EditText SearchInput_medicine;
private RecyclerView SearchResult_medicine;
private DatabaseReference allDocdatabaseref;
FirebaseRecyclerAdapter<FindMedicine,FindMedicineViewHolder> firebaseRecyclerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_medicine);
SearchResult_medicine = (RecyclerView) findViewById(R.id.search_result_list2);
SearchResult_medicine.setHasFixedSize(true);
SearchResult_medicine.setLayoutManager(new LinearLayoutManager(this));
SearchButton_medicine = findViewById(R.id.search_people_btn2);
SearchInput_medicine = (EditText) findViewById(R.id.Search_box_input2);
allDocdatabaseref = FirebaseDatabase.getInstance().getReference().child("MEDICINE");
SearchButton_medicine.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String searchBoxInput1 = SearchInput_medicine.getText().toString().trim();
SearchMedicine(searchBoxInput1);
}
});
}
private void SearchMedicine(String searchBoxInput1) {
Toast.makeText(this, "searching..", Toast.LENGTH_LONG).show();
Query searchmedicinequery = allDocdatabaseref.orderByChild("medicinename").startAt(searchBoxInput1).endAt(searchBoxInput1 + "\uf8ff");
firebaseRecyclerAdapter
= new FirebaseRecyclerAdapter<FindMedicine, FindMedicineViewHolder>(
FindMedicine.class,
R.layout.all_medicine_display_layout,
FindMedicineViewHolder.class,
searchmedicinequery
) {
@Override
protected void populateViewHolder(FindMedicineViewHolder viewHolder, FindMedicine model, int position) {
viewHolder.setMedicinename(model.getMedicinename());
}
};
SearchResult_medicine.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.startListening();
}
private class FindMedicineViewHolder extends RecyclerView.ViewHolder {
View mView;
public FindMedicineViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setMedicinename(String medicinename) {
TextView Docname = mView.findViewById(R.id.all_user_profile_name2);
Docname.setText(medicinename);
}
}
}
Я также использую геттер ..
package com.example.abed.smit;
public class FindMedicine {
public String medicinename;
public FindMedicine(String medicinename) {
this.medicinename = medicinename;
}
public String getMedicinename() {
return medicinename;
}
}
xml все allmedicine
<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_margin = "10dp"
android:background = "#000000">
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:orientation = "vertical"
android:layout_margin = "5dp">
<TextView
android:id = "@+id/all_user_profile_name2"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:text = "UserFullNAme"
android:textColor = "#91DC5A"
android:textSize = "18sp" android:textStyle = "bold"/>
</LinearLayout>
</LinearLayout>
find_medicine xml
<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
xmlns:tools = "http://schemas.android.com/tools"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:background = "#000000"
tools:context = ".FindMedicineActivity">
<RelativeLayout
android:id = "@+id/myLayout2"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_alignParentStart = "true"
android:layout_alignParentTop = "true"
android:layout_alignParentLeft = "true">
<EditText
android:id = "@+id/Search_box_input2"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginBottom = "20dp"
android:layout_marginLeft = "40dp"
android:layout_marginRight = "40dp"
android:drawableLeft = "@drawable/ic_action_name"
android:hint = "Enter Bmdc Number"
android:textColor = "#FFFFFFFF"
android:textColorHint = "#FFFFFFFF"
android:textSize = "16sp"
android:textStyle = "bold" />
<Button
android:id = "@+id/search_people_btn2"
android:layout_width = "170dp"
android:layout_height = "30dp"
android:layout_alignParentStart = "true"
android:layout_alignParentTop = "true"
android:layout_marginStart = "94dp"
android:layout_marginTop = "67dp"
android:background = "@drawable/buttonshape"
android:shadowColor = "#A8A8A8"
android:shadowDx = "0"
android:shadowDy = "0"
android:shadowRadius = "5"
android:text = "Confirm"
android:textColor = "#FFFFFF"
android:textSize = "20sp"
android:layout_alignParentLeft = "true"
android:layout_marginLeft = "94dp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id = "@+id/search_result_list2"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:layout_alignParentLeft = "true"
android:layout_alignParentStart = "true"
android:layout_below = "@+id/myLayout2"
android:layout_margin = "10dp"
android:background = "#000000"
>
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
готово сэр .. я добавил
Они оба кажутся хорошими.
да сэр ! вот почему я спросил!
сэр, svi.data выручайте пожалуйста!
Я пытаюсь прочитать и найти проблему.
Можете выложить изображение из базы данных или скетч?
попробуйте набрать набросок базы данных, чтобы наглядно ее увидеть.
я его разместил ... сэр ..
Не можете найти изображение, пожалуйста, избегайте ссылок?
сэр, у вас есть img?
Да, теперь МЕДИЦИНА - высший узел? или есть более высокий?
МЕДИЦИНА - высший узел, сэр ...
Я могу дать тебе свой проект, чтобы увидеть проблему!




Думаю, это проблема с доступом, теперь я не думаю, что в вашем приложении есть аутентификация. Итак, я предполагаю, что это проблема с правилами базы данных.
Проверьте вкладку правил в своей базе данных реального времени и сделайте это (если это не так):
".read":"true"
{"rules": {".read": true, ".write": true}}
@ABED устанавливает для них значение true, если это не так.
Убедитесь, что ваша учетная запись google service. json правильный
Измените свой запрос на -
Query searchmedicinequery = allDocdatabaseref.orderByChild("name").startAt(searchBoxInput1).endAt(searchBoxInput1 + "\uf8ff");
И согласно документу firebase - У класса есть пустой конструктор, который требуется для автоматического сопоставления данных Firebase.
Так что измените свою модель как -
public class FindMedicine {
public String name;
public FindMedicine() {
}
public FindMedicine(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
также добавьте xml активности (FindMedicineActivity).