我想通过点击按钮将一个包传递给新活动。 这是类适配器中bundle的代码,它扩展了recycleview adapter
private void passBundle (Vendor mItemSelected){
mBundle = new Bundle();
mBundle.putString("VENDOR_ID", mItemSelected.getVENDORID());
mBundle.putString("CAT_ID", "" + mItemSelected.getVEN_TYPE());
mBundle.putString("VENDOR_NAME", "" + mItemSelected.getVENDORNAME());
mBundle.putString("CAT_ID", "" + mItemSelected.getVEN_TYPE());
mBundle.putString("CAT_ID", "" + mItemSelected.getVEN_TYPE());
mBundle.putString("VENDOR_AREA", "" + mItemSelected.getVENDORADDRESS());
Intent in = new Intent(context,Chat_Activity.class);
in.putExtra("Bundle", mBundle);
Context.startActivity(in);
}
这是我在另一个活动中检索包数据的代码。
Bundle bundle = new Bundle();
chatVenID = bundle.getString("VENDOR_ID", "");
catID = bundle.getString("CAT_ID", "");
vendorName = bundle.getString("VENDOR_NAME", "");
vendorArea = bundle.getString("VENDOR_AREA","");
答案 0 :(得分:0)
您可以调用
Bundle bundle = getIntent().getBundleExtra("Bundle");
chatVenID = bundle.getString("VENDOR_ID", "");
在onCreate(Bundle savedInstanceState)方法中; new Bunlde()将创建一个新的bundle对象,无法从prev活动中获取pass值。
答案 1 :(得分:0)
Bundle bundle = new Bundle();
在此代码中,您正在创建Bundle的新对象,因此您不会获得任何值。将其更改为
getIntent().getBundleExtra("Bundle")