How to pass the image and text in the list view to another activity

advertisements

Possible Duplicate:
How to pass drawable between activities

I want to pass the image and text in this listview to another activity. Can someone explain to me how to pass image and text to another activity which displays both image and text

In the code there are two activities home activity and list_display in this list_display class created custom listview with image and text and I got the listview with image and text now I want to pass image and text to third activity which displays both image and text

Home Activity

    public void onClick(View v) {
    // TODO Auto-generated method stub
    if(v.getId()==R.id.iv_animals)
    {
        Intent intent=new Intent(Home_Activity.this,List_Display.class);
        intent.putExtra("type", "animal");
        startActivity(intent);
    }else if(v.getId()==R.id.iv_wild)
    {
        Intent intent=new Intent(Home_Activity.this,List_Display.class);
        intent.putExtra("type", "wild");
        startActivity(intent);
    }

package com.myown.kidszoo;

 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;

 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.BaseAdapter;
 import android.widget.GridView;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.SimpleAdapter;
 import android.widget.TextView;

  public class List_Display extends Activity implements OnItemClickListener {
Object animalArray[][]={{"animal",R.drawable.a_american_alligator,"ALIGATOR"},"animal",R.drawable.bear,"BEAR"},
                        {"animal",R.drawable.camel,"CAMEL"},{"animal",R.drawable.dog,"DOG"},
                        {"wild",R.drawable.elephant,"ELEPHANT"},{"wild",R.drawable.fox,"FOX"},
                        {"wild",R.drawable.giraffe,"GIRAFFE"},{"wild",R.drawable.hippopotamus,"HIPPOPOTAMUS"},

String i;
int lstIndex;
int pos;
public Context mContext;
@Override
public void onCreate(Bundle instance) {
    super.onCreate(instance);
    setContentView(R.layout.list_sample);
    i=getIntent().getExtras().getString("type");
    List<HashMap<String,Object>> nameList=new ArrayList<HashMap<String,Object>>();
    HashMap<String,Object> hm=new HashMap<String, Object>();
    if(i.equals("animal"))
    {
    for(int i=0;i<animalArray.length;i++) {
            hm.put("name", animalArray[i][1]);
            hm.put("image", animalArray[i][2]);
            nameList.add(hm);
    }}
    if(i.equals("wild"))
    {
    for(int i=0;i<animalArray.length;i++) {
            hm.put("name", animalArray[i][1]);
            hm.put("image", animalArray[i][2]);
            nameList.add(hm);
    }}

    ListView lv1=(ListView)findViewById(R.id.ListView1);
    String from[]={"image","name"};
    int to[]={R.id.iv_home_singlelist,R.id.tv_name_single};
    SimpleAdapter adapter=new SimpleAdapter(getApplicationContext(), nameList, R.layout.single_list, from, to);
    lv1.setAdapter(adapter);
    lv1.setOnItemClickListener(this);

}
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
    // TODO Auto-generated method stub
    Intent intent=new Intent(List_Display.this,Fullimage_Display.class);
    //
    // what data i need to give here to go to next activity
    startActivity(intent);

};
}


You cannot pass big image via intent's extra. But in your code, it seems all images are drawable resources. So you can just pass the resource id which is just "int" number, then reload image from resource in the next activity.