How to access parent Activity View in Fragment

前端 未结 4 1066
刺人心
刺人心 2021-01-31 06:58

I have an ActionBarActivity and fragment. I am using FragmentPagerAdapter that provides fragment to my app. My question How can I access parent Activit

4条回答
  •  一整个雨季
    2021-01-31 07:53

    At first, create a view like this:

    View view = getActivity().findViewById(R.id.viewid);
    

    Then convert it to any view that you need like this:

     if( view instanceof EditText ) {
                editText = (EditText) view;
                editText.setText("edittext");
                //Do your stuff
            }
    

    or

    if( view instanceof TextView ) {
      TextView textView = (TextView) view;
      //Do your stuff
    }
    

提交回复
热议问题