Hello friends,
ActivityMain.java
Thank you
ActivityMain.java
public class HomeActivity extends Activity {
public OnFragmentPassDataListeners getFragmentRefreshListener() {
return fragmentRefreshListener;
}
public void setFragmentPassDataListener(OnFragmentPassDataListeners fragmentRefreshListener) {
this.fragmentRefreshListener = fragmentRefreshListener;
}
private OnFragmentPassDataListeners fragmentRefreshListener;
private Button btnrefresh;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
btnrefresh = (Button)findViewById(R.id.btn);
btnrefresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (getFragmentRefreshListener() != null) {
getFragmentRefreshListener().onPassData("Hello Samset");
}
}
});
}
FragmentHome.java
public class FragmentHome extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
((HomeActivity) getActivity()).setFragmentPassDataListener(new OnFragmentPassDataListeners() {
@Override
public void onPassData(String data) {
Log.e("TAG"," Your massege"+data);
}
});
initView(view);
return view;
}
}
Thank you
No comments:
Post a Comment