Я думаю, что вы забыли добавить свой пакет к вашему фрагменту перед вызовом менеджера фрагментов.
Вы должны попробовать что-то вроде этого:
Small fSmall = new Small();
Bundle bundle = new Bundle();
bundle.putString("message_small", message_small); //parameters are (key, value).
fSmall.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment, fSmall).commit();
Во втором фрагменте вы должны проверить, не является ли myString
нулевым или пустым.
String myString = getArguments().getString("message_small");
if (myString == null) {
Log.e("TAG", "Error: null argument");
}
РЕДАКТИРОВАТЬ Я вижу еще одну проблему здесь.Вы получаете доступ к varaible, которые не были созданы.Вы должны надуть ваш макет перед вызовом findViewById()
, иначе он вернет NullPointerException
.
Обновите свой Small
класс следующим образом:
public class Small extends Fragment {
private EditText editText;
View myView;
public Small() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
myView = inflater.inflate(R.layout.fragment_small, container, false);
String myString = getArguments().getString("message_small");
// Here, myView is != null
TextView editText = myView.findViewById(R.id.small_text);
// Here, editText is != null
editText.setText(myString);
return myView;
}
}
Best