Naidan Naidan - 1 month ago 7
Java Question

ParseQuery from field not save

ItemCount field not working

CategoryModel constructs is ItemCount = 0 not working

ParseObject parseObjectCategory = Categorylist.get(i);

ParseQuery<ParseObject> query = ParseQuery.getQuery("List");
query.whereEqualTo("parent", parseObjectCategory);

query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
itemCount = scoreList.size();
Log.e("ItemCountGENERAL",""+itemCount);
} else {
Log.e("Aldaa","---------------------------------------------------------------");
}
itemCount = scoreList.size();
}
});

Log.e("ItemCount",""+itemCount);

if(name.equals("Inbox")){
categoryMode1= new CategoryModel(itemData,name,R.drawable.ic_inbox, itemCount);
}else if(name.equals("Stared")){
categoryMode1= new CategoryModel(itemData,name,R.drawable.ic_stars, itemCount);
}else{
categoryMode1= new CategoryModel(itemData,name,R.drawable.ic_inbox, itemCount);
}

mainData.add(categoryMode1);
mainAdapter.notifyDataSetChanged();
}`


My Image:

enter image description here


Help Me
www.google.mn

Answer

You should add these code

                    if(name.equals("Inbox")){
                        categoryMode1= new CategoryModel(itemData,name,R.drawable.ic_inbox, itemCount);
                    }else if(name.equals("Stared")){
                        categoryMode1= new CategoryModel(itemData,name,R.drawable.ic_stars, itemCount);
                    }else{
                        categoryMode1= new CategoryModel(itemData,name,R.drawable.ic_inbox, itemCount);
                    }

                    mainData.add(categoryMode1);
                    mainAdapter.notifyDataSetChanged();` 

into the FinalCallback. You got 0 for itemCount because you are calling in an uninitialized field. itemCount got its value inside the FinalCallback which runs in a separate non UI thread which means the UI thread from where you are accessing it may run before the non UI thread. So you should move you logic which uses data that is retrieved from parse into FinalCallback