onClick FloatingActionButton片段到活动

时间:2017-10-24 08:21:36

标签: android android-fragments

请。如何使用

将片段调用到活动
 FloatingActionButton tambahpendor=(FloatingActionButton)view.findViewById(R.id.floatingToko);
    tambahpendor.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent sae = new Intent(getActivity(), ImputToko_Activity.class);
            startActivity(sae);

        }
    });

2 个答案:

答案 0 :(得分:1)

你可以这样做:

FloatingActionButton tambahpendor=(FloatingActionButton)view.findViewById(R.id.floatingToko);
tambahpendor.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
       getImputTokoActivity();

    }
});

getImputTokoActivity()  {
        Intent sae = new Intent(getActivity(), ImputToko_Activity.class);
        startActivity(sae);
}

希望它有所帮助,因为有时java8功能是未知的。

答案 1 :(得分:0)

你必须这样做:

FloatingActionButton tambahpendor=(FloatingActionButton)view.findViewById(R.id.floatingToko);
tambahpendor.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.container, new FragmentName());
    transaction.commit();
}
});

其中container is the id of the main element in your activities xml file