目前,我主要使用 Fragments 来连接 Facebook。
但是,对于其他代码,我使用正常的活动(无片段)。
我现在的问题是,我希望有一个按钮可以从我的“主页”链接到片段,并从片段链接回我的“主页”
我无法这样做。
我尝试使用相同的代码在活动之间切换,但它不起作用。
有没有办法将正常活动链接到片段,反之亦然?或者它们只能相互链接吗?
这是我的代码:
public class SplashFragment extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.splash, container, false);
// return view;
Button btnNextScreen = (Button) view.findViewById(R.id.btnNextScreen);
// Button btnNextScreen = (Button) findViewById(R.id.btnNextScreen);
//Listening to button event
btnNextScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Starting a new Intent
Intent nextScreen = new Intent(**getApplicationContext()**, SecondScreenActivity.class);
startActivity(nextScreen);
}
});
return view;
}
}
我在 getApplicationContext() 处收到错误。
如果我将其更改为 getActivity(),他们将提示另一个错误,表明他们期望切换到 Fragment,而不是 Activity。
感谢您的帮助 !
问候,
Android学生
如果您想从片段导航到活动,请使用此 getActivity()。
Intent nextScreen = new Intent(getActivity(), SecondScreenActivity.class);
startActivity(nextScreen);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)