Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, 26 September 2017

Refresh fragment with interface

Hello friends,



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