Hello i have fragment inside of Activity. I have two Buttons one for fragment and activity. The job of button in fragment is get the value of edittext and the job of button on activity is get the value from button and set it to textview. This is my approach. MainActivity Button that will get the value and set it to MainActivity textview
public void onClick(View view){
Intent i = getIntent();
String name = getIntent().getStringExtra("name");
//SET DATA TO TEXTVIEWS
nameTxt.setText(name);
}
first (Fragment)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_first, container, false);
nameFragTxt= (EditText) root.findViewById(R.id.m1);
Button cxz = (Button)root.findViewById(R.id.ccc);
cxz.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getActivity(), Main2Activity.class);
i.putExtra("name",nameFragTxt.getText().toString());
}
});
return root;
}
Using startActivity(i);
is working but this is not i want. What do you guys think is the best approach to do this.