5

this is my data in Firestore I want to show this name "mouad"

This is my code

ublic class SearchActivity extends AppCompatActivity {

    private RecyclerView mMainList;
    private FirebaseFirestore mFirestore;
    private List usersList;
    private CustomAdapter adapterRe;
    EditText editText;
    Button btnSearch;
    String  name;

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

        mFirestore = FirebaseFirestore.getInstance();


        editText = (EditText) findViewById(R.id.search);
        btnSearch = (Button) findViewById(R.id.btn);

        usersList = new ArrayList();
        adapterRe = new CustomAdapter(getApplicationContext(), usersList);

        mMainList = (RecyclerView) findViewById(R.id.recyvle);
      //  mMainList.setHasFixedSize(true);
     //   mMainList.setLayoutManager(new LinearLayoutManager(this));
     //   mMainList.setAdapter(adapterRe);


        btnSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SearchUserFirebase();
            }
        });



    }

    private void SearchUserFirebase() {
        name = editText.getText().toString();
        if(!name.isEmpty()){

            Query query =  mFirestore.collection("Movies").orderBy("name" ).startAt(name).endAt(name + "\uf8ff");
            query.addSnapshotListener(new EventListener() {
               @Override
               public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {

                   if (e != null){

                       Log.d("TAG", "Error : " + e.getMessage());
                   }
                   ArrayList adsList = new ArrayList();

                   for(DocumentChange doc : documentSnapshots.getDocumentChanges()){

                       if (doc.getType() == DocumentChange.Type.ADDED){

                           Movies users = doc.getDocument().toObject(Movies.class);
                           usersList.add(users);
                           adapterRe.notifyDataSetChanged();

                       }
                   }

                   Log.d("TAG", "no of records of the search is " + adsList.size());

               }
           });

        }
    }
    }

This is error

error

q-l-p
  • 4,304
  • 3
  • 16
  • 36
mouad zizi
  • 307
  • 2
  • 9
  • Please add the code in text format and not in a picture. – Alex Mamo Jul 20 '18 at 17:03
  • Post the whole activity code @mouad zizi – Raj Jul 20 '18 at 17:07
  • Remove this lines from comment - // mMainList.setLayoutManager(new LinearLayoutManager(this)); // mMainList.setAdapter(adapterRe); and your error will be resolved. – Raj Jul 20 '18 at 19:44
  • Did that worked for you @mouadzizi ? – Raj Jul 21 '18 at 17:42
  • no it doesn't worck – mouad zizi Jul 21 '18 at 17:50
  • i fix it when i add this line in the loop mMainList.setAdapter(adapterRe); – mouad zizi Jul 21 '18 at 17:58
  • i have a new error + When I search for a word, I only get the addresses that start with the same word you entered Is there any way to bring me even the middle words inside the titles, for example This is the title of "Game of Throns" If only "throns" are introduced to any movie – mouad zizi Jul 21 '18 at 18:02
  • When I search for a word, the first letter begins with a smaller letter showing the result When the same word is pronounced but the first letter is large the result does not appear – mouad zizi Jul 21 '18 at 18:04

2 Answers2

3

Do you have an empty constructor inside the "Movies.java" file?

 public Movies() {
      //Necessary to retrieve data
 }
SLendeR
  • 839
  • 7
  • 25
2

Typically this error appears when you are trying to set the adapter from a background thread and not from the "main" thread (for example inside the onCreate() method).

If you are trying to set the adapter from a "delayed" method like inside the onEvent() method, this warning will always appear.

To solve this, move the creation of the adapter in the same thread and get the following line of code out of that for loop.

adapterRe.notifyDataSetChanged();
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • nothing !? the error stile TAG: no of records of the search is 0 – mouad zizi Jul 20 '18 at 19:00
  • i fix it when i add this line in the loop mMainList.setAdapter(adapterRe); – mouad zizi Jul 21 '18 at 17:58
  • When I search for a word, the first letter begins with a smaller letter showing the result When the same word is pronounced but the first letter is large the result does not appear – mouad zizi Jul 21 '18 at 18:04
  • i have a new error + When I search for a word, I only get the addresses that start with the same word you entered Is there any way to bring me even the middle words inside the titles, for example This is the title of "Game of Throns" If only "throns" are introduced to any movie – mouad zizi Jul 21 '18 at 18:04
  • Yes, you can take a look at my answer from this **[post](https://stackoverflow.com/questions/51452823/it-is-possible-to-have-a-contains-search-query-in-firebase/51456002)**. – Alex Mamo Jul 22 '18 at 09:04
  • not that i use Query it's work for me but didn't get all data had like names – mouad zizi Jul 22 '18 at 20:27