android 如何将listview的每个item中的值传到另一个Activity中
现在我是要把listview(每个item包含服务器中获取的图片和自己定义的一个顺序号)中的每一项item中的所有数据传到另一个Activity中,然后显示出来。但是我现...
现在我是要把listview(每个item包含服务器中获取的图片和自己定义的一个顺序号)中的每一项item中的所有数据传到另一个Activity中,然后显示出来。但是我现在出现的问题是显示不出来。我是菜鸟一个,希望各路大神帮我解决一下,看一下我的代码哪里出问题了,还有另一个activity接收参数那边应该怎么写。下面是我的代码
private ListView myQQ;
private byte pic;
public String[] names = new String[]{"01", "02", "03", "04", "05"};
private SimpleAdapter adapter=null;
private List<Map<String, Object>> items=new ArrayList<Map<String,Object>>();
private Bitmap bitmap;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.canyin);
Intent intent=getIntent();
Bundle bundle=intent.getExtras();
int length = bundle.getInt("length");
byte pic[] = bundle.getByteArray("data");
final Bitmap bitmap= BitmapFactory.decodeByteArray(pic,0,length);
int w = bitmap.getHeight();
int h = bitmap.getWidth();
Log.d("taoyouyou", "w : " + w + ", h : " + h);
myQQ = (ListView) findViewById(R.id.myQQ);//获取到下拉列表
for (int i = 0; i < 10; i++) {
Map<String, Object> item = new HashMap<String, Object>();
item.put("icon",bitmap);
item.put("name", names[i]);
this.items.add(item);
}
this.adapter = new SimpleAdapter(this, this.items, R.layout.item, new String[] {"icon", "name" }, new int[] { R.id.icon, R.id.name });
this.myQQ.setAdapter(this.adapter);
adapter.setViewBinder(new ViewBinder() {
@Override
public boolean setViewValue(View view, Object data,
String textRepresentation) {
if(view instanceof ImageView ){
ImageView iv=(ImageView)view;
iv.setImageBitmap(bitmap);
return true;
}else{
return false;
}
}
});
this.myQQ.setOnItemClickListener(new OnItemClickListenerImpl());
}
public class OnItemClickListenerImpl implements OnItemClickListener {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Intent intent=new Intent(canyin.this,discount.class);
Map<String, String> map = (Map<String, String>)myQQ.getItemAtPosition(arg2);
intent.putExtra("bitmap", map.get("bitmap"));
intent.putExtra("name", map.get("names"));
startActivity(intent);
}}<map<map</map</map 展开
private ListView myQQ;
private byte pic;
public String[] names = new String[]{"01", "02", "03", "04", "05"};
private SimpleAdapter adapter=null;
private List<Map<String, Object>> items=new ArrayList<Map<String,Object>>();
private Bitmap bitmap;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.canyin);
Intent intent=getIntent();
Bundle bundle=intent.getExtras();
int length = bundle.getInt("length");
byte pic[] = bundle.getByteArray("data");
final Bitmap bitmap= BitmapFactory.decodeByteArray(pic,0,length);
int w = bitmap.getHeight();
int h = bitmap.getWidth();
Log.d("taoyouyou", "w : " + w + ", h : " + h);
myQQ = (ListView) findViewById(R.id.myQQ);//获取到下拉列表
for (int i = 0; i < 10; i++) {
Map<String, Object> item = new HashMap<String, Object>();
item.put("icon",bitmap);
item.put("name", names[i]);
this.items.add(item);
}
this.adapter = new SimpleAdapter(this, this.items, R.layout.item, new String[] {"icon", "name" }, new int[] { R.id.icon, R.id.name });
this.myQQ.setAdapter(this.adapter);
adapter.setViewBinder(new ViewBinder() {
@Override
public boolean setViewValue(View view, Object data,
String textRepresentation) {
if(view instanceof ImageView ){
ImageView iv=(ImageView)view;
iv.setImageBitmap(bitmap);
return true;
}else{
return false;
}
}
});
this.myQQ.setOnItemClickListener(new OnItemClickListenerImpl());
}
public class OnItemClickListenerImpl implements OnItemClickListener {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Intent intent=new Intent(canyin.this,discount.class);
Map<String, String> map = (Map<String, String>)myQQ.getItemAtPosition(arg2);
intent.putExtra("bitmap", map.get("bitmap"));
intent.putExtra("name", map.get("names"));
startActivity(intent);
}}<map<map</map</map 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询