Passing data from fragment to mainactivity with tablayout and adapater. Kotlin android app

Viewed 85

i need help with the following situation. I hava a fragment, adapter and mainactivity. i use fragment and adapter for tablayout. Im trying to pass data from edittext in fragment to activity.

When i am using Intent to pass data from fragment to mainactivit , it crashes the app. Is there a another posibility to pass data like via adapter to mainactivity?

class person : Fragment() {


    lateinit var Sname : EditText



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }



    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        // Inflate the layout for this fragment

        return inflater.inflate(R.layout.fragment_person, container, false)
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        Sname= view.findViewById(R.id.snamedittext)

        senddata()

    }



private fun  senddata() {

    var name = Sname.toString()


   val intent = Intent(activity,personactivity::class.java)
   intent.putExtra("name", name)

    startActivity(intent)



}



}

0 Answers
Related