我使用 AndroidBegin 指南用 Parse.com 表( http://www.androidbegin.com/tutorial/android-parse-com-simple-listview-tutorial/ )中的数据填充我的 ListView,它显示了一个空的 ListView。
// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(QuestionsList.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
if (AnswerActivity.friend.isEmpty()) {
if (AnswerActivity.wantedTop == AnswerActivity.all) {
// Locate the class table named "Info" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Info");
// Locate the column named "Views" in Parse.com and order list by ascending
query.orderByDescending("Views");
try {
ob = query.find();
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
} else {
// Locate the class table named "Info" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Info");
// Search for the wanted topic
query.whereContains("User_Topic", AnswerActivity.wantedTop);
// Locate the column named "Views" in Parse.com and order list by ascending
query.orderByDescending("Views");
try {
ob = query.find();
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
} else {
if (AnswerActivity.wantedTop == AnswerActivity.all) {
// Locate the class table named "Info" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Info");
// Search for the wanted topic
query.whereContains("User_Name", AnswerActivity.friend);
// Locate the column named "Views" in Parse.com and order list by ascending
query.orderByDescending("Views");
try {
ob = query.find();
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
} else {
// Locate the class table named "Info" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Info");
// Search for the wanted topic
query.whereContains("User_Topic", AnswerActivity.wantedTop);
query.whereContains("User_Name", AnswerActivity.friend);
// Locate the column named "Views" in Parse.com and order list by ascending
query.orderByDescending("Views");
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>(QuestionsList.this,
R.layout.listview_item);
// Retrieve object "name" from Parse.com database
for (ParseObject country : ob) {
adapter.add((String) country.get("name"));
}
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
// Capture button clicks on ListView items
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Send single item click data to SingleItemView Class
Intent i = new Intent(QuestionsList.this,
SingleItemView.class);
// Pass data "name" followed by the position
i.putExtra("name", ob.get(position).getString("name")
.toString());
// Open SingleItemView.java Activity
startActivity(i);
}
});
}
}
后来,我使用了 ParseQueryAdapter 教程,但还是不行。
有人知道怎么做吗?