【问题标题】:Start activity from a AdapterRecyclerView从 AdapterRecyclerView 启动活动
【发布时间】:2017-10-27 04:48:09
【问题描述】:

我有一个带有一些片段的viewPager(在一个片段中我有一个recyclerView),recyclerView 包含更多项目,所以,当我单击recyclerView 上的一个项目时,我想它转换为@ 987654326@。但我不明白。

错误 非常感谢

【问题讨论】:

  • 请不要发布代码、XML 或 logcat 输出的屏幕截图。请将所有文本作为文本发布。

标签: android android-fragments android-recyclerview start-activity


【解决方案1】:

试试这个

Intent intent= new Intent(itemView.getContext(),addsongList.class);
itemView.getContext().startActivity(intent);

【讨论】:

  • @Danh 很乐意为您提供帮助
【解决方案2】:

像这样更改您的代码或在您的adapter 中传递Context

Intent intent= new Intent(itemView.getContext(),AddSongToList.class);
getActivity.startActivity(intent);

【讨论】:

    【解决方案3】:

    你需要一个上下文来调用startActivity()。将 getActivity() 作为上下文从您初始化适配器的片段传递;喜欢:

    YourAdapter adapter = new YourAdapter(getActivity, /* other parameters*/);
    

    在适配器中:

    private Context mContext;
    
    YourAdapter(Context context, /*other parameters*/) {
        mContext = context;
    }
    

    然后使用mContext调用startActivity():

    mContext.startActivity();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-17
      • 2011-10-25
      • 1970-01-01
      相关资源
      最近更新 更多