1

I have a ListView created . and when I click a single item of the ListView, I'm calling an activity to show the single item View. TextView data is parsing. but when I'm trying to call an image from parse its not loading (the image is hosted in a separate location online). if any one can please tell how to load image here ??

my file url

url = new URL("file location " + statusObject.getString("image"));

edited code

   URL url = null;
                    try {
                        url = new URL("https://www.gravatar.com/avatar/db5bfe41c9d21d3a5b4e5b5f6a2d776d?s=32&d=identicon&r=PG&f=1");
                    } catch (MalformedURLException e1) {
                        e1.printStackTrace();
                    }
                    Bitmap bmp = null;
                    try {
                        bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                    txtv2.setImageBitmap(bmp);

////////////////

single item view

import android.content.*;
import android.net.*;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.*;
import android.view.View;
import android.widget.*;

import com.parse.*;
import com.parse.ParseException;

public class SingleItemView extends AppCompatActivity {

    String objectId;
    protected TextView txtv;
    protected TextView txtv1;
    protected ImageView txtv2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_single_item_view);


        txtv =(TextView)findViewById(R.id.txt123);
        txtv1 =(TextView)findViewById(R.id.txt1234);
        txtv2 =(ImageView)findViewById(R.id.txt12345);
        Intent i =getIntent();

        objectId = i.getStringExtra("objectId");

        ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");
        query.getInBackground(objectId, new GetCallback<ParseObject>() {
            public void done(ParseObject object, ParseException e) {
                if (e == null) {

                    String username = object.getString("firstname");
                    txtv.setText(username);
                    String position = object.getString("position");
                    txtv1.setText(position);
                    String img_ = object.getString("image");
                    txtv2.setImageURI(Uri.parse(img_));

                } else {
                    // something went wrong
                }
            }
        });



    }

}

fragment file

import android.content.*;
import android.os.Bundle;
import android.support.v4.app.*;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import java.util.ArrayList;
import java.util.List;

public class Individuals extends android.support.v4.app.ListFragment
        implements FindCallback<ParseObject> {

    private List<ParseObject> mOrganization = new ArrayList<ParseObject>();
    SearchView sv;
    IndividualsAdaptor adaptor;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.individuals, container, false);
    }
    @Override
    public void onViewCreated(View view, Bundle b) {
        super.onViewCreated(view, b);
        sv = (SearchView) view.findViewById(R.id.ser1);
        adaptor = new IndividualsAdaptor(getActivity(), mOrganization);
        setListAdapter(adaptor);
        ParseQuery.getQuery("_User").findInBackground(this);

        sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String text) {
                return false;
            }
            @Override
            public boolean onQueryTextChange(String text) {
                adaptor.getFilter().filter(text);
                return true;
            }
        });
    }
    @Override
    public void done(List<ParseObject> scoreList, ParseException e) {
        if (e == null) {
            Log.d("score", "Retrieved " + scoreList.size() + " _User");
            mOrganization.clear();
            mOrganization.addAll(scoreList);
            ((IndividualsAdaptor) getListAdapter()).updateBackupList(mOrganization);
            ((IndividualsAdaptor) getListAdapter()).notifyDataSetChanged();
        } else {
            Log.d("score", "Error: " + e.getMessage());
        }
    }

   @Override
    public void onListItemClick(android.widget.ListView l, android.view.View v, int position, long id) {
        super.onListItemClick(l, v, position, id);

        ParseObject prs = mOrganization.get(position);
        String objectId = prs.getObjectId();
        Intent i = new Intent(getActivity(), SingleItemView.class);
        i.putExtra("objectId", objectId);
        startActivity(i);

    }
}
Faizal Munna
  • 515
  • 5
  • 21

2 Answers2

1

Define <uses-permission android:name="android.permission.INTERNET" /> in Manifest.xml.

Then use Picasso or Gilde and parse images from their respective instances and pass image URL that you are querying from parsing. These libraries will parse URL and return image in the ImageView.

Other similar questions: Load image from url

How to load an ImageView by URL in Android?

Community
  • 1
  • 1
Sneh Pandya
  • 8,197
  • 7
  • 35
  • 50
  • your first link is working after some edits .. but only for a placeholder image can you tell how to laod a dynamic image check my question i updated @Sneh Pandya – Faizal Munna Feb 22 '17 at 07:38
1

finally this code is working after editing some codes form the link in the answer . by this code you can call images dynamically for each of the Object id.

 URL url = null;
                        try {
                            url = new URL("image url" + object.getString("image"));
                        } catch (MalformedURLException e1) {
                            e1.printStackTrace();
                        }
                        Bitmap bmp = null;
                        try {
                            bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }
                        txtv2.setImageBitmap(bmp);

                        // something went wrong
Faizal Munna
  • 515
  • 5
  • 21