可能重复:
如何在活动之间传递drawable
我想将此列表视图中的图像和文本传递给另一个活动。有人可以向我解释如何将图像和文本传递给另一个同时显示图像和文本的活动
在代码中有两个活动 home 活动和 list_display 在这个 list_display 类中创建了带有图像和文本的自定义列表视图,我得到了带有图像和文本的列表视图现在我想将图像和文本传递给第三个显示图像和文本的活动
家庭活动
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);
};
}