3

在以下代码中,我在 HighScore 类中搜索按升序排序的最佳时间结果。所以我得到了最好的结果列表。我遇到的困难是将每次结果的名称和学校名称添加到列表中。(请参阅附图)

private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
    // Override this method to do custom remote calls
    protected Void doInBackground(Void... params) {
        // Gets the current list of bestTime in sorted order
        ParseQuery query = new ParseQuery("TestsTopRecords");
        query.orderByAscending("bestTime");

        try {
            results = query.find();
        } catch (ParseException e) {

        }
        return null;
    }

    @Override
    protected void onPreExecute() {
        HighScoreTable.this.progressDialog = ProgressDialog.show(HighScoreTable.this, "",
                "Loading...", true);
        super.onPreExecute();
    }

    @Override
    protected void onProgressUpdate(Void... values) {

        super.onProgressUpdate(values);
    }

    @Override
    protected void onPostExecute(Void result) {
        // Put the list of results into the list view
        ArrayAdapter<Double> adapter = new ArrayAdapter<Double>(HighScoreTable.this,R.layout.todo_row);
        for (ParseObject object : results) {
            adapter.add((Double) object.get("bestTime"));
        }
        setListAdapter(adapter);
        HighScoreTable.this.progressDialog.dismiss();
        TextView empty = (TextView) findViewById(android.R.id.empty);
        empty.setVisibility(View.VISIBLE);
    }
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_high_score_table);

    TextView empty = (TextView) findViewById(android.R.id.empty);
    empty.setVisibility(View.INVISIBLE);

    new RemoteDataTask().execute();
    registerForContextMenu(getListView());
}

我希望它看起来如何

Prase.com 数据库的屏幕截图

4

1 回答 1

0

这可能是最简单的方法。

使用String代替Double并执行此操作

ArrayAdapter<String> adapter = new ArrayAdapter<String>(HighScoreTable.this,R.layout.todo_row);
for (ParseObject object : results) {
    adapter.add((Double) object.get("bestTime") + " " + object.getString("Name") + " " + object.getString("SchoolAndCity"));
}
于 2013-09-15T05:38:46.997 回答