这就是我的表现。
使用适配器首先存储数据,然后将其附加到微调器
在 oncreate 中定义djtry().execute()
。
private class DjTry extends AsyncTask<Void,Void,Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(CreateClasstalk.this);
// Set progressdialog title
mProgressDialog.setTitle("Parse.com Simple ListView Tutorial");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Locate the class table named "Country" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"Country");
query.orderByAscending("country_name");
try {
ob = query.find();
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Locate the listview in listview_main.xml
// listview = (ListView) findViewById(R.id.listview);
// Pass the results into an ArrayAdapter
adapter = new ArrayAdapter<String>(CreateClasstalk.this,
R.layout.example_item);
// Retrieve object countrt_name from Parse.com database
for (ParseObject country : ob) {
adapter.add((String) country.get("country_name"));
Log.d("DJ ADAPTER",country.toString());
}
country.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
答案 0 :(得分:1)
尝试使用
adapter = new ArrayAdapter<String>(
context, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
为什么不从doInBackground()返回ob,这样你就会在onPostExecute(Object ob)中收到ob