I have two fragments.addfragment and control fragment. From addfragment I send the data using bundle with fragment transaction and then in control fragment,I want to get that data using bundle but I can't get data. so plz help me
Here is my addfragment with fragment transaction-
relaylist.setAdapter(adapter);
relaylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
HashMap<String, String> o = (HashMap<String, String>) relaylist.getItemAtPosition(position);
Log.e("ip: ", "> " + o.get("ip"));
Log.e("port: ", "> " + o.get("port"));
Log.e("uname: ", "> " + o.get("uname"));
Log.e("password: ", "> " + o.get("password"));
ControlFragment fragment = new ControlFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
Bundle bundle = new Bundle();
bundle.putString("ip", o.get("ip"));
bundle.putString("port", o.get("port"));
bundle.putString("uname", o.get("uname"));
bundle.putString("password", o.get("password"));
Log.e("ip: ", "> " + o.get("ip"));
Log.e("port: ", "> " + o.get("port"));
Log.e("uname: ", "> " + o.get("uname"));
Log.e("password: ", "> " + o.get("password"));
fragment.setArguments(bundle);
transaction.replace(R.id.mainFrame, new ControlFragment() );
transaction.commit();
}
});
and In control fragment I get data this way...but I can't get data
public class ControlFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView= inflater.inflate(R.layout.fragment_control, container, false);
Bundle bundle = getArguments();
String ip=bundle.getString("ip");
Stirng port = bundle.getString("port");
Stirng uname = bundle.getString("uname");
Stirng password = bundle.getString("password");