我不确定在从解析中检索数据时如何添加进度条或创建加载对话框。 这是我的代码,用于从解析中检索数据。我尝试了很少的教程,但似乎没有一个对我有用。
public class HolidayActivity extends AppCompatActivity {
private HolidayAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_holiday);
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setIcon(R.drawable.dl);
ParseObject.registerSubclass(Holiday.class);
mAdapter = new HolidayAdapter(this, new ArrayList<Holiday>());
ListView mListView = (ListView) findViewById(R.id.holiday_list);
mListView.setAdapter(mAdapter);
updateData();
}
public void updateData() {
ParseQuery<Holiday> query = ParseQuery.getQuery(Holiday.class);
query.setCachePolicy(ParseQuery.CachePolicy.CACHE_THEN_NETWORK);
query.findInBackground(new FindCallback<Holiday>() {
@Override
public void done(List<Holiday> holidays, com.parse.ParseException e) {
if (holidays != null) {
mAdapter.clear();
for (int i = 0; i < holidays.size(); i++) {
mAdapter.add(holidays.get(i));
}
}
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; goto parent activity.
this.finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
答案 0 :(得分:0)
将此添加到您的updateData()
:
public void updateData() {
final ProgressDialog progressDialog = ProgressDialog.show(this, null, "Loading…");
(…)
@Override
public void done(List<Holiday> holidays, com.parse.ParseException e) {
progressDialog.dismiss();
(…)
}
}
希望它有所帮助!