0

I have a listview containing image and name in activity-A. When i clicked on listview,it has to move to another activity-B.

In activity-B, one imageButton is there. when i clicked on any item in listview in activity-A, the image corresponding to that clicked item has to display in activity-B's imageButton

i searched more but not get proper answer.

Please suggest me the bast answer to solve this problem

Thanks in advance...

balu...
  • 221
  • 2
  • 3
  • 13

2 Answers2

2

I hope below code is useful to u.

1st Actvity

ListView listView;
int total_data = 11;

// references to our images
private Integer[] mThumbIds = { R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6,
        R.drawable.sample_7, R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3, R.drawable.sample_4,
        R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2,
        R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7 };

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    listView = (ListView) findViewById(R.id.listView1);
    listView.setAdapter(new ImageAdapter());

    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub

            Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                    mThumbIds[arg2]);

            Intent intent = new Intent(StackTestActivity.this,
                    StackTestActivity1.class);
            intent.putExtra("bitmap", bitmap);

            startActivity(intent);

        }
    });
}

private class ImageAdapter extends BaseAdapter {

    public ImageAdapter() {

    }

    public int getCount() {
        return mThumbIds.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {

        View v;
        if (convertView == null) {
            LayoutInflater li = getLayoutInflater();

            v = li.inflate(R.layout.customview, null);

        } else {
            v = convertView;
        }

        TextView text = (TextView) v.findViewById(R.id.textView1);
        text.setText("Image Text");

        ImageView icon = (ImageView) v.findViewById(R.id.imageView1);
        icon.setImageResource(mThumbIds[position]);

        return v;
    }

}

2nd Actvity

ImageView button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second);

    button=(ImageView)findViewById(R.id.imageView1);

    Bundle extra=getIntent().getExtras();

    if(extra!=null)
    {
        Bitmap bitmap = (Bitmap) getIntent().getParcelableExtra("bitmap");
        button.setImageBitmap(bitmap);
    }

}
Dhaval Khant
  • 2,467
  • 2
  • 16
  • 24
  • Thank you very much........ please can you suggest for this: In my application i have a google map. i did programming for that.... in emulator i got google map also but when i loaded that application in TABLET, application loaded successfully...it asking login and password also . after this ,the google map has to open, in tablet,its showing error" Application stopped unexpectedly",but in emulator its working very fine .... any suggestion .. thank you – balu... Nov 24 '11 at 10:44
0

you can check here for some answers regarding this issue: Get/pick an image from Android's built-in Gallery app programmatically

In general, supposing you have saved the image in a place, you can either send an intent in order to view it via the gallery or you can open the file, read it, and then set it to the ImageView.

Hope this helps!

Community
  • 1
  • 1
Dimitris Makris
  • 5,183
  • 2
  • 34
  • 54
  • hi thanks for response. already images are loaded into listview. if i clicked on list means, the image have to send to next activity's imagebutton.. i tried by taking id,positon but no use.... is there any way to take image's reference from listview only and send the copy of image to another activity .? – balu... Nov 24 '11 at 09:25
  • When you download the images, you could store them in (i.e.) a HashMap with image_url, image. Then when clicking on a list item you can get the position of the list item or the reference to the specific image you clicked and send that reference. There is no reason to send the whole image object to the other Activity. – Dimitris Makris Nov 24 '11 at 09:28
  • in my application i have a google map. i did programming for that.... in emulator i got google map also but when i loaded that application in TABLET, application loaded successfully...it asking login and password also . after this ,the google map has to open, in tablet,its showing error" Application stopped unexpectedly",but in emulator its working very fine .... any suggestion .. thank you – balu... Nov 24 '11 at 09:47