addy123
addy123

Reputation: 524

To Pull images from Parse.com

I have saved some images to Parse.com from my Mobile album and I'm trying to fetch and display the images in a list-view in another activity which I'm not able to. I have searched the documentation but could not resolve it.Here is my class.

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();
}

With the help of 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();
    }
}}

Kindly help if there is any API for accessing data on Parse.com thanx!

Upvotes: 2

Views: 856

Answers (1)

user3110424
user3110424

Reputation:

In your code every thing is fine. You have to fill the

imagelist = new ArrayList<Images>(); 

when you are getting the image in doInBackground(Void... params) try to add imagelist.add(Image.get("ImageFile")); in your Async's Task doInBackground(Void... params) method. Thats all.

Upvotes: 1

Related Questions