-4

I am beginner in android. I am trying to find a way to transfer the text from the editText of an an activity to the fragment so that the result is displayed in the textview of the fragment.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

1

you can use bundle to transfer data from activity to fragment

I suppose data will be sent on button click.

Bundle bundle = new Bundle();
bundle.putString("from_activity", edittext.getText().toString());
Fragmentclass fragment= new Fragmentclass();
fragment.setArguments(bundle);

In fragment

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view;
    view=inflater.inflate(R.layout.fragment, container, false);

    String text= getArguments().getString("from_activity"); 
  TextView tv=(TextView)findViewById(R.id.yourTextView);
   tv.setText(text);   
    return view;
}
santosh kumar
  • 2,952
  • 1
  • 15
  • 27