我试图用一堆字符串来更新我的ListView,但现在它是如何工作的,当我调用updateClassesList()方法它没有更新ListView。我也搞乱了onResume(),这也让它消失了。建议表示赞赏!
private ArrayAdapter<String> classListAdapter;
private List<String> classes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mClassesListView = (ListView) findViewById(R.id.classesListView);
mEmptyListTextView = (TextView) findViewById(R.id.emptyListTextView);
mProgressBar =(ProgressBar) findViewById(R.id.progressBar);
mProgressBar.setVisibility(View.INVISIBLE);
mClassesListView.setAdapter(classListAdapter);
updateClassesList();
}
private void updateClassesList() {
if(isNetworkAvailable()) {
classes = new ArrayList<String>();
toggleRefresh();
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser == null) {
navigateToLogin();
} else {
Log.i(TAG, currentUser.getUsername());
}
ParseQuery<ParseObject> query = ParseQuery.getQuery("Classes");
if (currentUser != null) {
query.whereEqualTo("username", currentUser.getUsername());
}
query.orderByAscending("createdAt");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> classesList, ParseException e) {
toggleRefresh();
if (e == null) {
Log.d("Classes", "Retrieved " + classesList.size() + ": " + classesList);
for (int i = 0; i < classesList.size(); i++) {
classes.add(classesList.get(i).getString("classTitle") + "");
Log.d(TAG, classesList.get(i).getString("classTitle"));
}
} else {
Log.d("Classes", "Error: " + e.getMessage());
}
}
});
classListAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, classes);
mClassesListView.setAdapter(classListAdapter);
}
else{
Toast.makeText(this,"No network connection", Toast.LENGTH_SHORT).show();
}
}