1

i am using a list that is pupolated with a custom adaptor that extends CursorAdaptor, i would like to download images while doing it and place them in the adapter layout, i use intentService to download the image i get it back with a reciver, now i have my image in my onRecive finction but i am buffled as to how i can place it in a view that is in the new CursorAdapter, anybody knows?

the Cursor Adapter:

public class MyAdapter extends CursorAdapter{

    public MyAdapter(Context context, Cursor c) {
        super(context, c);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void bindView(View view, Context context, Cursor c) {


        String name = c.getString(c.getColumnIndex(ContractPlaces.Places.NAME));
        String address = c.getString(c.getColumnIndex(ContractPlaces.Places.ADDRESS));
        String type = c.getString(c.getColumnIndex(ContractPlaces.Places.TYPE));
        float rating = c.getFloat(c.getColumnIndex(ContractPlaces.Places.RATING));
        String icon = c.getString(c.getColumnIndex(ContractPlaces.Places.ICON));

        TextView nameView = (TextView) view.findViewById(R.id.name);
        TextView addressView = (TextView) view.findViewById(R.id.address);
        TextView typeView = (TextView) view.findViewById(R.id.type);
        TextView ratingView = (TextView) view.findViewById(R.id.rating);

        ImageView iconView = (ImageView) view.findViewById(R.id.icon);

        nameView.setText(name);
        addressView.setText(address);
        typeView.setText("Type: "+type);
        ratingView.setText("Rating: "+String.valueOf(rating));


        // iconView - this is where i would like to place tha image from the reciver    

    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        // TODO Auto-generated method stub
            return getActivity().getLayoutInflater().inflate(R.layout.cursor_layout, parent, false);
        }


class ImageReceiver extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {

            Bitmap b = intent.getParcelableExtra("image");
//this is the image i would like to place in the view "iconView"

        }
Ziv Kesten
  • 1,206
  • 25
  • 41

2 Answers2

0

Its being a lengthy process to download the image in Intent Service and get that image to adapter class. If you are Interested I have a solution for you.

Use Universal Image Loader library for downloading image. You need not worry about anything. The library itself consists of so many in-built methods. you can use them.

see this thread for using Universal Image Loader

Naveen
  • 1,948
  • 4
  • 17
  • 21
0

You are not allowed to pass any data type directly through the intent except boolean, integer, string, Char, Float and the other primitive data types.

Passing any other type will be via parcelable intent. Using parcelable you can pass any object whatever its type. Here is an example of the parcelable and how to use it

OR

Create a public method called newInstance(Object o) and in this method call your default constructor and set your object value as following:

public MyActivity newInstance(MyObject o){
    MyActivity activity = new MyActivity();
    this.myObject = o;
    return activity;
} 
Community
  • 1
  • 1
Sami Eltamawy
  • 9,874
  • 8
  • 48
  • 66