Search code examples
androidjsonimageuniversal-image-loader

Cannot display image (form JSON) in detail activity from search reasult?


I spent three days and didn’t find working solution to display image in detail view. Because I use search view I have to use more difficult way which doesn't work. I’m using Universal Image Loader in ListActivity but have no idea how to implement it in DetailView. TextView text is displaying correct in DetailView. I see while debuging, url of the image in ’extras’ (or ’intent’) in ’mMap’ value, but can’t display it. ’ flag’ variable is null. 'flagImg' doesn't constain image url. I tryied with getParacetable, Bitmap, but I always get null in flag value.

ListActivity:

    public ListAdapter(Context context, List<MovieModel.Descriptions> items) {
        this.context = context;
        this.items = items;
        inflater = (LayoutInflater.from(context));
        this.arrayList = new ArrayList<MovieModel.Descriptions>();
        this.arrayList.addAll(items);
    } 
    view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {

        Intent intent = new Intent(context, DetailActivity.class);
        intent.putExtra("flag",(items.get(position).getImage()));
        intent.putExtra("getInfo",(items.get(position).getInfo()));
        context.startActivity(intent);
        }
        });
        return view;
        }

public void filter(String charText){
        charText = charText.toLowerCase(Locale.getDefault());
        items.clear();;
        if(charText.length() == 0) {
        items.addAll(arrayList);
        }else{
        for(MovieModel.Descriptions wp : arrayList){
        if(wp.getTitle().toLowerCase(Locale.getDefault()).contains(charText))
        items.add(wp);
        }
        }
        notifyDataSetChanged();
        }

In Detail Activity

     int flag;
        int send;
        // recovering data
        Intent i = getIntent();
        info = i.getStringExtra("getInfo");
        detInfo = (TextView)findViewById(R.id.info);
        detInfo.setText(info);

        flag = i.getIntExtra("flag", send);
        flagImg = (ImageView)findViewById(R.id.detailImg);
        flagImg.setImageResource(flag);

// Two of 9 solutions I used:
// bitmap is null
//        flagImg = (ImageView)findViewById(R.id.detailImg);
//        Bitmap bitmap = (Bitmap) i.getParcelableExtra("flag");
//        flagImg.setImageBitmap(bitmap);

//  bmp is null:
//        Bundle extras = getIntent().getExtras();
//        Bitmap bmp = (Bitmap) extras.getParcelable("flag");
//        detImg.setImageBitmap(bmp);


            // How add this image to Universal Image Loader ?
            ImageLoader.getInstance().displayImage(flagImg.setImageResource(flag),flagImg, new ImageLoadingListener() {...

Solution

  • I will suppose that you are passing correct url via intent so in your DetailActivity:

    String flag;
    flag = i.getStringExtra("flag");
    flagImg = (ImageView)findViewById(R.id.detailImg);
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.displayImage(flag, flagImg);