我有带有图像的ExpandableListView,当点击子时,它会在新活动中打开相同的图像。
我没有"抓住" drawable(例如R.drawable.twitter)在有意图传递时的位置,所以如果你能解释一下插入 myIntent.putExtra("图像",此处);我真的很感激!
数组列表:
ArrayList<Country> countryList = new ArrayList<Country>();
Country country = new Country("Where do I sign", R.drawable.twitter, "Tom Cruise", "TOP GUN");
countryList.add(country);
country = new Country("Count me in", R.drawable.facebook, "Jonah Hill", "21 JUMP STREET");
countryList.add(country);
country = new Country("Show me the money", R.drawable.facebook, "Tom Cruise", "JERRY MAGUIRE");
countryList.add(country);
Continent continent = new Continent("Yes",countryList);
continentList.add(continent);
countryList = new ArrayList<Country>();
country = new Country("I cant' do that", R.drawable.facebook, "Robert De Niro", "GOODFELLAS");
countryList.add(country);
country = new Country("Forget about it", R.drawable.facebook, "Johny Deep", "DONIE BRASCO");
countryList.add(country);
country = new Country("You have no power here", R.drawable.facebook, "Bernard Hill", "LORD OF THE RINGS");
countryList.add(country);
continent = new Continent("No",countryList);
continentList.add(continent);
国家/地区类:
public class Country {
private String code = "";
private int Image;
private String actor = "";
private String movie = "";
public Country(String code, int Image, String actor, String movie) {
super();
this.code = code;
this.Image = Image;
this.actor = actor;
this.movie = movie;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public int getImage() {
return Image;
}
public void setImage(int Image) {
this.Image = Image;
}
public String getActor() {
return actor;
}
public void setActor(String actor) {
this.actor = actor;
}
public String getMovie() {
return movie;
}
public void setMovie(String movie) {
this.movie = movie;
}
}
意图活动A:
myList.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2,
int arg3, long arg4) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(MainActivity.this, StartActivity.class);
myIntent.putExtra("image", ------);
MainActivity.this.startActivity(myIntent);
return false;
}
});
getIntent Activity B:
Intent myIntent = getIntent();
int image = myIntent.getIntExtra("image", 0);
ImageView imagefull = (ImageView)findViewById(R.id.imageView1);
imagefull.setImageResource(image);
答案 0 :(得分:0)
试试这个
myIntent.putExtra("image", myList.get(position).getImage());
然后在getIntentActivity中使用它。
希望它有所帮助!!!