简体   繁体   English

在TextView上继续进行其他活动和/或片段,请单击

[英]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.

相关问题 单击另一个片段中的按钮后,在片段中添加新的文本视图 - Add new textview in fragment after click on button in another fragment 当我单击TextView ID时,如何将一个片段转到另一个片段? - How to go one Fragment to another when I will click on TextView Id? 单击时片段活动崩溃 - Fragment activity crash on click 删除另一个片段活动中的片段 - Removing a fragment in another fragment activity 从活动的工厂将时间和日期的字符串传递到另一个片段的textview时出错 - Error while passing string from time&date from an activity's fab to another fragment's textview 在对其他片段执行操作后,如何从动态更改的textview更改? - How to change dynamically inflated textview from after proceeding an action on other fragment? 如何在Drawable上的另一个活动上单击ImageView和另一个图像显示在TextView上 - How to Click on ImageViews And another image Display On TextView on Another Activity From Drawable 使用ViewPager从Activity更改Fragment TextView - Change Fragment TextView from Activity using ViewPager 尝试更新TextView时Activity中的片段崩溃 - Fragment in Activity crashing when trying to update TextView 如何在其他活动中为片段TextView充气 - How to inflate fragment TextView in other activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM