Using Parse.com for the first time . Here's the problem,I am trying to query the Parse.com and then displaying it in android listview Log is getting printed properly but some issue in displaying it in listview
Here's the code
ArrayList<String> mFuncDate = new ArrayList<String>();
private ListView lv;
lv = (ListView) findViewById(R.id.myList);
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
//Log.d("score", "Retrieved " + scoreList.size() + " in list " + scoreList.get(0).getString("ClientName"));
for(int i=0;i<scoreList.size();i++) {
Log.d("data","Retrieved Object is " + scoreList.get(i).getString("Date"));
mFuncDate.add( scoreList.get(i).getString("Date"));
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
//String arr[]=mFuncDate.toArray(new String[mFuncDate.size()]);
lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 ,android.R.id.text1 ,mFuncDate));
Where am I going wrong ?
Updated:
The problem is I can not see data getting updated in my listview, After trying so much time When I run this app when my screen is off I can see the listview getting updated but then normally I can not see anything in the listview ... I think it is something related to findInBackground so need help
I tried to update the listview by calling listAdapter.notifyDataSetChanged() after querying is done, in order for the list to repaint using the new data.
Related
I have problem with Parse. I'm making something like Shopping List App and I can't find solution. Here is the problem:
I have clean app without connection to internet yet, but will be. I'm making offline shopping lists now so I'm creating list and pin to local database like this:
ParseObject list = new ParseObject("ShoppingList");
list.put("name", listNameString);
list.put("status", "0");
list.put("deadline",textDate.getText().toString());
list.pinInBackground();
Objects offline do not have ID.
Next I'm trying to add some products to this in next activity.
I have object of ShoppingList and new product and I'm trying to do something like this:
saveProductB.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ParseObject product = new ParseObject("ProductOfList");
product.put("name", productName.getText().toString());
product.put("status", "0"); //status wykupienia produktu
product.put("amount", productAmount.getText().toString());
product.put("category", productCategory.getSelectedItem().toString());
product.put("description", productDescription.getText().toString());
product.put("measure", productMeasure.getSelectedItem().toString());
product.put("icon", productIcon.getText().toString());
product.put("belongsToOffline", list);
product.pinInBackground();
Intent intent = new Intent(AddProductToList.this,ShoppingListDetailsActivity.class);
intent.putExtra("LIST_OBJECT", list);
startActivity(intent);
}
});
but without unique ID I have no possibility to get object with this:
ParseQuery<ParseObject> query = ParseQuery.getQuery("ProductOfList");
query.fromLocalDatastore();
query.whereEqualTo("belongsToOffline",list);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(final List<ParseObject> scoreList, ParseException e) {
if (e == null) {
for(ParseObject s : scoreList){
}
Log.d("score", "Retrieved " + scoreList.size() + " scores");
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
with list.get("name") instead of list inside belongsToOffline everything is ok but I need to let user to make various lists with the same name.
Any solution?
Thank you in advance.
I'm making a small application. trying to retrieve posts inserted, and then I want to retrieve only new inserted posts, and not retrieving all the posts again.
So do you have any idea on how to I can retrieve last items ( Since the list object retrieved)
Here my Query code :
public void getFeed(int limit, int skip){
ParseQuery<ParseObject> query = ParseQuery.getQuery("Feed");
query.setSkip(skip);
query.setLimit(limit);
query.setCachePolicy(ParseQuery.CachePolicy.CACHE_ELSE_NETWORK);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> feedList, ParseException e) {
if (e == null) {
for (int i = 0; i < feedList.size(); i++) {
Post p = new Post(feedList.get(i).get("Text").toString());
mAdapter.addItem(p);
}
Log.d("result", "Here is it:" + feedList.size());
mRecyclerView.setAdapter(mAdapter);
} else {
Log.d("Feed", "Error: " + e.getMessage());
}
}
});
}
keep the last time you checked and then use that time to pull anything greater than the last time checked from the createdAt column or updatedAt column (if its possible for someone to update something you are pulling) of the object. then after your query is finished update that time to the current time.
you can store the viewed posts count and next time when retrieving the list set the count as parameter for skip:
query.setSkip(count);
I'm using Parse and I'm doing a query to fetch a table .
As you can see in the code below, the list LOCALparseQuestionList is populated correctly during the for loop inside the findInBackground. Once it's done, the LOCALparseQuestionList is empty (the log prints 0 size and I see the same when using the debugger).
How should I fetch correctly the data and populate my LOCALparseQuestionList?
public List<QuestionStruct> getParseAllQuestions() {
final List<QuestionStruct> LOCALparseQuestionList = new ArrayList<QuestionStruct>();
// Select All Query
ParseQuery<ParseObject> questionQuery = ParseQuery.getQuery("triviaQuestions");
questionQuery.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> allQuestions, ParseException e) {
if (e == null) {
parseQuestionList = allQuestions;
Log.d(TAG, "Retrieved " + allQuestions.size() + " All questions");
for (ParseObject qu : allQuestions) {
QuestionStruct currentQuestion = new QuestionStruct();
currentQuestion.setID(qu.getInt("id"));
currentQuestion.setQuestion(qu.getString("question"));
currentQuestion.setCorrectAnswer(qu.getString("correct"));
currentQuestion.setPossibleAnswer(qu.getString("wrong_1"));
currentQuestion.setPossibleAnswer(qu.getString("wrong_2"));
currentQuestion.setPossibleAnswer(qu.getString("wrong_3"));
currentQuestion.setPossibleAnswer(qu.getString("correct"));
LOCALparseQuestionList.add(currentQuestion);
Log.d(TAG, "Retrieved " + LOCALparseQuestionList.size() + " LOCALparseQuestionList ");
}
} else {
Log.d(TAG, "Error: " + e.getMessage());
}
}
});
Log.d(TAG, "questionList size: " + LOCALparseQuestionList.size());
return LOCALparseQuestionList;
}
Its a the number one misunderstanding about asynchronous functions: the code underneath the find function does not run after the find function. It runs before it.
The last log statement in the function logs, and the return statement returns an empty list, because that list is populated later, after the find is done and the results are returned. Anything you do that depend on LOCALparseQuestionList being populated must be done within the find's callback.
I am new to android, am developing one application in which i have to get the data from the server need to store that data in sqlite, so every time i should not hit the server,when ever i want get from database,in this app i used fragment concept,when i enter the single character in multiautocomplete textview based on the names in json response it needs to show the email-ids which are matching to that character in drop down list. i have done the code am not getting errors but not getting the expected result in textview
when i debug the code the following block of code is not executing i don't know what is the problem in this can you please help me any one
new Handler().post(new Runnable() {
public void run() {
Cursor cursor = contactDataSource.getAllData();
if (BuildConfig.DEBUG)
Log.d(TAG, "total contcat count :" + cursor.getCount());
while (cursor.moveToNext()) {
if (BuildConfig.DEBUG)
Log.d(TAG,
"Contact from cursor:"
+ cursor.getString(cursor
.getColumnIndex(ExistingContactTable.COL_NAME)));
}
customAdapter = new CustomContactAdapter(getActivity(), cursor);
Log.i("Custom contact adapter", "" + customAdapter);
if (customAdapter != null)
editorIdSharableEmail.setAdapter(customAdapter);
}
});
First get your all data in array by json
and then use that array
String[] str={"Andoid","Jelly Bean","Froyo",
"Ginger Bread","Eclipse Indigo","Eclipse Juno"};
MultiAutoCompleteTextView mt=(MultiAutoCompleteTextView)
findViewById(R.id.multiAutoCompleteTextView1);
mt.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
ArrayAdapter<String> adp=new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,str);
mt.setThreshold(1);
mt.setAdapter(adp);
if you dont know how to get data from json then check this and also check this
This is doing my head in. I got this working in iOS in about 10 mins. Clearly I'm missing something. I'm simply trying to pull data out of parse.com into a textfield. I have found lots of examples but none explaining why it's not working correctly. Below is the code pulled from parse.com site and jiggyed with. Incidentally it's wigging out on totemList.getString particularly the "getString" part.
ParseQuery<ParseObject> query = ParseQuery.getQuery("Birds");
query.whereEqualTo("totemName", "Pigeon");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> totemList, ParseException e) {
if (e == null) {
Log.d("score", "Retrieved " + totemList.size() + " scores");
String totemDesc = totemList.getString("totemDesc");
//Get the Totems Description
TotemDescription = (TextView)findViewById(R.id.animalDesc);
TotemDescription.setText(totemDesc);
} else {
Log.d("score", "Error: " + e.getMessage());
// something went wrong
TotemDescription = (TextView)findViewById(R.id.animalDesc);
TotemDescription.setText("not bob");
}
}
});
List<> does not have a getString() method.
List<ParseObject> totemList
Perhaps what you wanted to do was to iterate over your list of ParseObject get all the descriptions:
String descriptions = null;
for (ParseObject totem : totemList) {
if (descriptions == null) {
descriptions = totem.getString("totemDesc");
} else {
descriptions = descriptions + ", " + totem.getString("totemDesc");
}
}
Something like that. Then set the resulting string as text of your text field
TotemDescription.setText(descriptions);
If you have more than one ParseObject in your List<> your text will be something like:
Pigeon Totem, Another Pigeon Totem