Java 当我单击TextView Id时,如何将一个片段转到另一个片段?
当我单击TextView Id时,如何将一个片段转到另一个片段 错误显示: java.lang.ClassCastException:com.example.tripigator.Overview不能强制转换为android.app.Activity 错误来自以下几行:Java 当我单击TextView Id时,如何将一个片段转到另一个片段?,java,android,Java,Android,当我单击TextView Id时,如何将一个片段转到另一个片段 错误显示: java.lang.ClassCastException:com.example.tripigator.Overview不能强制转换为android.app.Activity 错误来自以下几行: TextView overview = (TextView) findViewById(R.id.txt_overview); overview.setOnClickListener(new View.O
TextView overview = (TextView) findViewById(R.id.txt_overview);
overview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ProjectOverview.this, Overview.class);
startActivity(intent);
}
});
所以,请任何人帮助我如何通过点击文本项从一个片段移动到另一个片段
ProjectOverview类:
布局界面:
您不应该在片段中使用意图来移动另一个片段 检查一下这个例子 用这个
((yourfragmentActivity) getActivity()).setCurrentItem(1,//desired activity 0=first 1= second and so on
true);
代替
Intent intent = new Intent(ProjectOverview.this, Overview.class);
startActivity(intent);
您无法使用Intent启动片段。请尝试此操作,它会有所帮助
Fragment fragment = null;
FragmentManager frgManager;
FragmentTransaction ft;
fragment = new Overview();
ft = frgManager.beginTransaction();
ft.replace(R.id.frame_content, fragment);
ft.addToBackStack(null);
ft.commitAllowingStateLoss();
如果使用查看寻呼机
your_ViewPager.setCurrentItem(position)
概述不是活动片段,因此您不能开始使用“开始活动”。@Hareshchelana我知道概述不是活动片段。但我不知道我将写什么代码,请给我发送代码,根据上述代码将一个片段移动到另一个片段。请帮助我。@Alam XML设计中的视图寻呼机在哪里。签出这个和这个@M S Gadag请给我完整的代码,以便根据上述代码将一个片段移动到另一个片段。请
Intent intent = new Intent(ProjectOverview.this, Overview.class);
startActivity(intent);
Fragment fragment = null;
FragmentManager frgManager;
FragmentTransaction ft;
fragment = new Overview();
ft = frgManager.beginTransaction();
ft.replace(R.id.frame_content, fragment);
ft.addToBackStack(null);
ft.commitAllowingStateLoss();
your_ViewPager.setCurrentItem(position)