I want to retrieve data from parse.com and show it in listview. but when i retrieve it and it shows me in hashcode. I have pasted picture of output.Please look into my query code and correct me.
Here is code for pulling data from parse.com
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> list, ParseException e) {
if (e != null) {
Toast.makeText(getActivity(), "Error" + e, Toast.LENGTH_SHORT).show();
} else {
for (ParseUser user : list) {
ParseUser newUser = new ParseUser();
newUser.getString(user.getString("username"));
newUser.getString(user.getString("Latitude"));
newUser.getString(user.getString("Longitude"));
newUser.getString(user.getString("Bloodtype"));
newUser.getString(user.getString("Mobile"));
user1.add(newUser);
}
ArrayAdapter<ParseUser> adapter = new ArrayAdapter<>(getActivity(),android.R.layout.simple_list_item_1,user1);
setListAdapter(adapter);
}
}
});
ArrayAdapter just use the toString of each object in the array.
Every user that you add to list is displayed as a pointer, this is the to string method of the ParseUser object.
If you are trying to display all information about the user you should create a custom adapter and implement the getView method.
If you want to check for now if it works correctly you can pass a list of just username for example and check if it works, then you can move on and implement your own adapter.
Edit:
For creating custom adapter check this question
Related
I'm trying to make a parse query from my activity. It's working fine, i'm able to retrieve my objects but there are always empty (ie match.user1 always null)
ParseUser user = ParseUser.getCurrentUser();
ParseQuery<Match> query = ParseQuery.getQuery(Match.class);
query.whereEqualTo("user1", user);
query.include("user1");
query.include("user2");
query.findInBackground(new FindCallback<Match>() {
#Override
public void done(List<Match> list, ParseException e) {
if(e == null){
// list[0].user1 = null
}
}
});
In my ApplicationController
ParseObject.registerSubclass(Match.class);
Parse.enableLocalDatastore(this);
Parse.initialize(this, "XXX", "XXX");
What's wrong in my code ?
Thanks
Try get the references object (in your case columns 'user1' and 'user2') as following:
list.get(0).getParseObject('user1')
this give you the reference object then you can access it's values (columns) user the getters methods
I am creating an app in android that allows the user to search other users registered in the app.
Each user is asked to enter a set of details like "Date of Birth" before entering into the app.These data are directly stored in the user class.
My requirement is that if a user enters a username and searches he must be able to see all the details available on that particular user.
For eg.:Lets assume every user must have a email(String) and date of birth(String).An User searches for name "John". What should the query be so that I can retrieve both email and DOB of a user with username "John".
The data given in the Parse.com guide is
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", name);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
Toast.makeText(getApplicationContext(),"Query Success",Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),"Query Not Successful",Toast.LENGTH_LONG).show();
}
}
});
What are the changes that I need to make so that I can achieve my goal?
How to access the string stored inside the object?
If I retrieve multiple records from my query how can I handle it?
I have edited my query like this
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereMatches("username", name);
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
for(ParseUser singleobject:objects){
String mail=singleobject.get("email").toString();
Toast.makeText(getApplicationContext(),mail,Toast.LENGTH_LONG).show();}
} else {
Toast.makeText(getApplicationContext(),"Query Not Successful",Toast.LENGTH_LONG).show();
}
}
});
No toast is generated but the query is executed without any exception.
Is the looping statement correct or am i doing something wrong??
What are the changes that I need to make so that I can achieve my goal?
The code looks like it correctly queries ParseUser for an exact match of a username. To match more loosely, consider using whereMatches
How to access the string stored inside the object?
Parse.Object provides getString() as well as other "get" variations depending on the attribute type.
If I retrieve multiple records from my query how can I handle it?
The "objects" parameter of the findInBackground completion handler is an array that contains zero or more matches to the query. Handle this array the way you would any other.
I have a parse class named "classA". I want to build a query where I want to search for rows in "classA" having certain "objectId". I have written the following code. But it always returns an empty list of ParseObjects. I have tried with separate columns existing in "classA". All the time, empty list returned. Please help.
I have used this query before on another class "classB" inside the same application and that works perfectly. I have also tried, "try-catch" block implementation using "query.find". That also returns empty list. Thanks in advance. Please explain what's wrong.
Need more code snippets, please let me know.
Button btn = (Button) findViewById(R.id.query_btn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText objIdET= (EditText) findViewById(R.id.obj_id);
String objId= objIdET.getText().toString();
Log.d("check", objId); // Prints correct value here..
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("classA");
fridgeID.whereEqualTo("objectId", objId);
List<ParseObject> lp = new ArrayList<ParseObject>();
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
Log.d("#results", String.valueOf(objects.size()));
}
});
}
}
});
Replace FridgeId with query
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("classA");
query.whereEqualTo("objectId", objId);
List<ParseObject> lp = new ArrayList<ParseObject>();
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
Log.d("#results", String.valueOf(objects.size()));
}
});
Use getInBackground() if you have objectId of that row.
ParseQuery<ParseObject> query = ParseQuery.getQuery("classA");
query.getInBackground(objId, new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
Log.d("#results", String.valueOf(objects.size()));
} else {
// Handle the error
}
}
}
Call findInBackground() if you don't have objectId and setting some condition. You can also set condition on objectId field like this.
ParseQuery<ParseObject> query = ParseQuery.getQuery("classA");
query.whereEqualTo("objectId", objId);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
Log.d("#results", String.valueOf(objects.size()));
} else {
// Handle the error
}
}
}
You are getting an empty list of Parse objects because there aren't any rows corresponding to the user (which you are logged in with).
Parse.com implements privacy of its data by using a field called ACL. So if user A adds an entry to your table, by default the ACL is set to Read+Write for User A and none for other users. So user B will not be able to find any objects of userA.
To read more : https://parse.com/docs/android/guide#security
If you want to create a mechanism by which only users belonging to a certain group can read+write each other's objects, you can Roles (Parse feature).
https://parse.com/docs/android/guide#roles
Check if you have set the correct keys when you initialize the parse in your application.
If you want to get list of users, and ParseQuery.getQuery doesn't work - try this:
val query: ParseQuery<ParseUser> = ParseUser.getQuery()
query.findInBackground() {...}
I am writing an address book APP and using the Parse service.
I also use the listview and BaseAdapter to implement the APP
There are many people I saved as the ParseObject.
And each ParseObject includes a photo saved as file.
I get all ParseObjects by :
ArrayList<ParseObject> list = new ArrayList<ParseObject>();
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("member");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
list = (ArrayList<ParseObject>) objects;
mMyadapter = new MyAdapter(context, list);
}
else {
}
});
in the adapter, I want to show the image from the ParseFile
My question is :
How do I get the ParseFile from the list?
I tried below code but the APP will shut down suddenly.
I wrote the getView method in the MyAdapter like below:
ParseFile pf = (ParseFile) list.get(position).get("photo1");
pf.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] bytes, ParseException e) {
if (e == null) {
Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
viewTag.imageView1.setImageBitmap(bm);
}
else {
Log.d("debug", "bad");
}
}
});
I can not use the getUrl() neither....
Can someone tell me how to modify it? Many thanks for your help!
You don't need to initialize list.
How are you setting the adapter of your ViewGroup? At the moment, you're creating a new adapter only when your ParseQuery is done. Your adapter may not be set properly.
Since list could point to new ArrayList<ParseObject>() or (ArrayList<ParseObject>) objects depending on whether ParseQuery is done, it's possible that you're calling list.get() on an invalid position.
In short, make your member variables local. Also, if MyAdapter is an anonymous class, pull that code out into a static inner class so it doesn't refer to its containing class' member variables. Use getItem() to access your ParseObjects, not list.get().
Using the Parse SDK for android, I'm trying to receive a ParseUser from a query, the following code is what I have tried:
ParseQuery<ParseUser> query = ParseUser.getQuery();
Follow.include("author");
query.whereEqualTo("User", "Alex");
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// This is where I want to receive the ParseUser from the List<ParseUser>
ParseUser pu = objects.get("author");
} else {
}
} });
Object.get("author") creates errors.
Thankyou for reading :)
ParseUser pu = objects.get("author"); would be incorrect usage. Get method is generally used to get a object at a particular position in the list.
The query returns a list of ParseUsers which you have named as objects.
Now use an iterator to go through the list to access each ParseUser.
like this
for(ParseUser pu : objects){
//access the data associated with the ParseUser using the get method
//pu.getString("key") or pu.get("key")
}
Hope this helps!