这是我的容器活动Table_info
,我想将数据从容器活动传递给它的子片段Table_no
。但我收到片段中的字符串为null
.
Table_info 的代码:
package com.example.androiddbconnection;
import android.content.Intent;
import android.os.Bundle;
android.support.v4.app.FragmentActivity;
import android.util.Log;
public class Table_info extends FragmentActivity {
String restaurant;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tableinfo_frag);
Intent in=getIntent();
Bundle bundle = getIntent().getExtras();
restaurant = bundle.getString("outletname");
Log.d("in mainactivity",restaurant);
Bundle bundle1 = new Bundle();
bundle1.putString("restaurant",restaurant);
Table_no fragment=new Table_no();
fragment.setArguments(bundle1);
}
}
这是我的片段Table_no:
public class Table_no extends Fragment {
String restaurant12;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle=getArguments();
if (bundle == null) {
Toast.makeText(getActivity(),"argum is null", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getActivity(),"argume", Toast.LENGTH_LONG).show();
restaurant12=bundle.toString();
Log.d("arguments", restaurant12);
}
}
但我得到的回应是'argum is null'