[英]Proceeding to another activity and/or fragment on TextView click
this is some text lyl this is some text lyl this is some text lylthis is some text lyl this is some text lyl this is some text lyl 这是一些文字lyl这是一些文字lyl这是一些文字lyl这是一些文字lyl这是一些文字lyl这是一些文字lyl
public void click(View v){
Intent intent;
switch(v.getId()){
case R.id.nav_Courses:
fragment = new CoursesActivity();
break;
Try this to open an Activity
from your Fragment
. 尝试此操作从
Fragment
打开一个Activity
。
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_start_page, container, false);
final Textview textview = view.findViewById(R.id.date_apr);
textview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), ItemDetailActivity.class);
startActivity(intent);
}
});
return view;
}
To open a Fragment you can use this code in another onclickListener. 要打开片段,您可以在另一个onclickListener中使用此代码。
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.container,new CoursesActivity,"");
transaction.addToBackStack(null);
transaction.commit();
container is the FrameLayout of your first Fragment. 容器是第一个Fragment的FrameLayout。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.