Get view of Fragment from FragmentActivity

前端 未结 5 1747
一个人的身影
一个人的身影 2021-01-01 10:09

I have a FragmentActivity where I add a Fragment. Depending on some situation, I want to access Buttons from that fragment\'s layout

5条回答
  •  滥情空心
    2021-01-01 10:44

    Simply Use the getRootView() method to get the data of your fragment in Activity.

    //below block of code write in activity.
    
    EditText et = (EditText) v.getRootView().findViewById(R.id.name);
    Log.d("Name", et.getText().toString());
    

    name is the field of fragment.

提交回复
热议问题