quickstart-android icon indicating copy to clipboard operation
quickstart-android copied to clipboard

Retrieve data by search

Open judytraj007 opened this issue 10 years ago • 6 comments

I'm trying to retrieve a child object if one of its fields matches a given value. This is my database fb This is my code for search...please help me out

(imgbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                key = search.getText().toString().trim();
                Firebase newRef = new Firebase("https://stockmanager-142503.firebaseio.com/Items");
                Query query = newRef.orderByChild("Idno").equalTo(key);
                query.addChildEventListener(new ChildEventListener() {
                    @Override
                    public void onChildAdded(DataSnapshot dataSnapshot, String s) {

                        Map<String,Item> td = (HashMap<String,Item>) dataSnapshot.getValue();

                        List<Item> valuesToMatch = new ArrayList<Item>(td.values());
                        myAdapter myadapter=new myAdapter(getActivity(),valuesToMatch);
                        mlistView.setAdapter(myadapter);
                    }

                    @Override
                    public void onChildChanged(DataSnapshot dataSnapshot, String s) {

                    }

                    @Override
                    public void onChildRemoved(DataSnapshot dataSnapshot) {

                    }

                    @Override
                    public void onChildMoved(DataSnapshot dataSnapshot, String s) {

                    }

                    @Override
                    public void onCancelled(FirebaseError firebaseError) {

                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                        builder.setMessage(firebaseError.getMessage())
                                .setTitle("Error!")
                                .setPositiveButton(android.R.string.ok, null);
                        AlertDialog dialog = builder.create();
                        dialog.show();


                    }
                });)

judytraj007 avatar Sep 20 '16 14:09 judytraj007

@Katniss394 what exactly is the problem you are having? I understand what you're trying to do but you haven't provided any indication of what is going wrong.

Also this does not seem to be related to code in this repository. You are using the old Firebase SDK and not referencing any of the Android quickstarts here. I would suggest moving this question to StackOverflow, as that's a better venue for troubleshooting.

samtstern avatar Sep 20 '16 15:09 samtstern

Nothing happens. I don't get a result. The onChildAdded method is not triggered

judytraj007 avatar Sep 20 '16 15:09 judytraj007

@Katniss394 there are a lot of reasons that could happen and I'd need more information to debug. As I said it's not really relevant to this repository though, so please open a question on StackOverflow.

samtstern avatar Sep 20 '16 15:09 samtstern

I've done that already. But no help.

judytraj007 avatar Sep 21 '16 06:09 judytraj007

http://stackoverflow.com/questions/39558397/display-firebase-child-objects-in-listview

judytraj007 avatar Sep 21 '16 06:09 judytraj007

did u get the solution

13BQ1A0538 avatar Sep 11 '17 11:09 13BQ1A0538