如何在android上查询解析表到listview?

时间:2015-03-04 15:29:22

标签: android android-listview parse-platform

我现在已经尝试了一段时间,但我的所有方法都失败了。最近我看到了一个例子,我尝试了它但它也失败了。

这是我的代码,如果有人能看到我出错的地方我试图从名为Projects的解析中获取包含以下属性的表: IDNameCategoryDescriptionStudents并将其放入ListView进行展示

import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;


public class UserPage extends ListActivity {
private List<Projects> projects;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_user_page);

    projects = new ArrayList<Projects>();

    ArrayAdapter<Projects> adapter = new ArrayAdapter<Projects>(this,
            R.layout.activity_user_page, projects);
    setListAdapter(adapter);

    refreshPostList();
}

private void refreshPostList(){
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Projects");

    final ProgressDialog mProgress;
    mProgress = new ProgressDialog(UserPage.this);
    mProgress.setTitle("Generating Projects");
    mProgress.setMessage("Loading...");
    mProgress.setIndeterminate(false);
    mProgress.show();

    query.findInBackground(new FindCallback<ParseObject>(){
        @SuppressWarnings("unchecked")
        public void done(List<ParseObject> projectList,ParseException e){
            if(e==null){
                projects.clear();
                for(ParseObject post :projectList){
                    Projects project = new Projects(post.getObjectId(),post.getString("ProjectName"), post.getString("Category"), post.getString("Description"), post.getString("Students"));
                    projects.add(project);
                }
                ((ArrayAdapter<Projects>) getListAdapter()).notifyDataSetChanged();
            }else{
                Log.d(getClass().getSimpleName(),"Error:"+ e.getMessage());
            }
        }
    });



}

0 个答案:

没有答案