从Parse.com拉出图像

时间:2014-01-10 06:34:52

标签: android android-listview imageview parse-platform

我已经从我的手机相册中将一些图像保存到Parse.com,我正试图在另一个我无法进行的活动中以列表视图的形式获取和显示图像。我搜索了文档,但无法解决它。这是我的课。

public class GetImage extends Activity {
// Declare Variables
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ListAdapter adapter;

private ArrayList imagelist = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from listview_main.xml
    setContentView(R.layout.listview_main);
    // Execute RemoteDataTask AsyncTask
    new RemoteDataTask().execute();
}

借助AsyncTask

private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Create a progressdialog
        mProgressDialog = new ProgressDialog(GetImage.this);
        // Set progressdialog title
        mProgressDialog.setTitle("Parse.com Custom ListView");
        // Set progressdialog message
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        // Show progressdialog
        mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        // Create the array
        imagelist = new ArrayList<Images>();
        try {
            // Locate the class table named "Country" in Parse.com
            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                    "Image");              
            query.orderByAscending("ImageFile");
            ob = query.find();
            for (ParseObject pb : ob) {

                ParseFile image = (ParseFile) Image.get("ImageFile");

            }
        } 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.listView1);
        // Pass the results into ListViewAdapter.java
        adapter = new ListAdapter(GetImage.this,
                imagelist);
        // Binds the Adapter to the ListView
        listview.setAdapter(adapter);
        // Close the progressdialog
        mProgressDialog.dismiss();
    }
}}

如果有任何用于访问Parse.com上的数据的API,请提供帮助!

1 个答案:

答案 0 :(得分:1)

在你的代码中,每件事都很好。你必须填写

imagelist = new ArrayList<Images>(); 

当您在doInBackground(Void... params)中获取图片时,请尝试在imagelist.add(Image.get("ImageFile"));任务Async's方法中添加doInBackground(Void... params)。多数民众赞成。