Android通过intent传值,无法接收到值,代码如下:
传递:@OverridepublicvoidonItemClick(AdapterView<?>arg0,Viewarg1,intarg2,longarg3){//TOD...
传递:@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
int dealerId=(Integer) dealerList.get(arg2).get("dealerId");
Intent intent=new Intent();
intent.setClass(getActivity(), DealerActivity.class);
intent.putExtra("dealerId", dealerId);
System.out.println(dealerId);
startActivity(intent);
}
接收:
Intent intent=getIntent();
String dealerId=intent.getStringExtra("dealerId");
System.out.println("dealerId:-----"+dealerId);
打印出来的id是null 展开
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
int dealerId=(Integer) dealerList.get(arg2).get("dealerId");
Intent intent=new Intent();
intent.setClass(getActivity(), DealerActivity.class);
intent.putExtra("dealerId", dealerId);
System.out.println(dealerId);
startActivity(intent);
}
接收:
Intent intent=getIntent();
String dealerId=intent.getStringExtra("dealerId");
System.out.println("dealerId:-----"+dealerId);
打印出来的id是null 展开
3个回答
展开全部
1.传值
Bundle bundle = new Bundle();
bundle.putString("dealerid", dealerid);
Intent intent = new Intent(getActivity(),DealerActivity.class);
intent.putExtras(bundle);
startActivity(intent);
2.接收
String dealerid = (String) getIntent().getExtras().get("dealerid");
更多追问追答
追问
我的错在哪里?
不能putstring
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询