Retrieve data by search
I'm trying to retrieve a child object if one of its fields matches a given value.
This is my database
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();
}
});)
@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.
Nothing happens. I don't get a result. The onChildAdded method is not triggered
@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.
I've done that already. But no help.
http://stackoverflow.com/questions/39558397/display-firebase-child-objects-in-listview
did u get the solution