The Bundle only passes data to another Fragment if it does not pass through the attach.
Fragment does not communicate directly with another Fragment, Fragment has to communicate with Activity and Activity communicates with Fragment B (this if the 2 Fragments are Up and running), so you have to use an interface.
example:
1) Interface
public interface OnCommunicateInterface
{
void onSetText(String str);
}
2) MainActivity
public class MainActivity extends FragmentActivity implements OnCommunicateInterface
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onSetText(String str)
{
FragmentReceiveData f2 = (FragmentReceiveData) getSupportFragmentManager().findFragmentById(R.id.frag_rec_data);
f2.updateText(str);
}
}
3) Fragment that will send Data
public class FragmentSendData extends Fragment
{
EditText editText;
Button button;
OnCommunicateInterface onCommunicate;
@Override
/****************** onCreateView *****************/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle b)
{
View v = inflater.inflate(R.layout.fragment_send_data,container,false);
editText = (EditText)v.findViewById(R.id.editText);
button = (Button)v.findViewById(R.id.button);
View.OnClickListener listener = new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String str = editText.getText().toString();
onCommunicate.onSetText(str);
}
};
button.setOnClickListener(listener);
// Inflate the layout for this fragment
return (v);
}
@Override
/**************** onAttach **************/
public void onAttach(Context context)
{
super.onAttach(context);
try
{
onCommunicate = (OnCommunicateInterface) context;
}
catch (Exception e)
{
Log.e("onAttach",e.toString());
}
}
}
4) Fragment that will receive Date
public class FragmentReceiveData extends Fragment
{
TextView textView;
@Override
/************** onCreateView() ******************/
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.fragment_receive_data,container,false);
textView = (TextView)v.findViewById(R.id.text_view);
// Inflate the layout for this fragment
return (v);
}
/*************** updateText() ********************/
public void updateText(String string)
{
textView.setText(string);
}
}
The cidogo is a bit ugly, but to be easy to understand and a simple example.
I hope it helps.