如何使用按钮调用班级

时间:2014-01-26 18:28:21

标签: java android class

我想使用片段中创建的按钮来调用类。这是包含按钮的片段的代码。

public class FragmentSecondPage extends Fragment{

    View root;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle){
        root = inflater.inflate(R.layout.fragment_page2, container, false); 
        return root;
    }
}

我想从infragment_page2按钮启动一个类SplashActivity.class。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:2)

//Create Intent that would call the Next Activity and since you are in Fragment you need to call getActivity() instead of this
Intent myIntent = new Intent(getActivity(), SplashActivity.class);
// This function will replace the currently running activity with new one
getActivity().startActivity(myIntent);