Я добавил это в приложение в mainActivity
bundle.putString("phone",FragmentManager.findFragment<SecondFragment> (View(this)).view?.findViewById<EditText>(R.id.phone_signup)?.text.toString())
После этого у меня при вызове этого крашится приложения... из за чего это? В чем проблема?
Сам editText
в fragment_second.xml
<EditText
android:id="@+id/phone_signup"
android:layout_width="200dp"
android:layout_height="40dp"
android:hint="@string/phone"
android:textColorHint="@color/grey"
android:textColor="@color/black"
android:background="@drawable/input_text"
android:layout_gravity="center"
android:layout_marginBottom="85dp"
android:gravity="center"
android:ems="10"
android:inputType="phone"/>
Код MainActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
fun toastMe(Str: String) {
val myToast = Toast.makeText(this,Str, Toast.LENGTH_SHORT)
myToast.show()
}
fun RegistrationCallFragment() {
val bundle = Bundle()
bundle.putString("phone",
FragmentManager.findFragment<SecondFragment>(View(this)).view?.findViewById<EditText>(R.id.phone_signup)?.text.toString()
)
bundle.putString("email",
FragmentManager.findFragment<SecondFragment>(View(this)).view?.findViewById<EditText>(R.id.email_signup)?.text.toString()
)
bundle.putString("password",
FragmentManager.findFragment<SecondFragment>(View(this)).view?.findViewById<EditText>(R.id.pasword_signup)?.text.toString()
)
Registration_second.getNewInstance(args = bundle)
}
}
код из фрагмента где я принимаю эти данные
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
//val extras = getIntent()?.getExtras();
//if(extras != null) {
// val phone = extras.getString("phone", "")
// val email = extras.getString("email", "")
// val password = extras.getString("password", "")
//return inflater.inflate(R.layout.fragment_registration_second, container, false)
val phone = arguments?.getString("phone", "")
val email = arguments?.getString("email", "")
val password = arguments?.getString("password", "")
Log.d("PHONE BLYAT", phone+email+password+"THis")
print(phone+email+password)
val activ = activity
(activ as MainActivity).toastMe(phone.toString())
return inflater.inflate(R.layout.fragment_registration_second, container, false)
}