如何从片段中的RecyclerView适配器启动活动

Panupong Chirasathain

我无法点击RecyclerView到一个新ActivityRecyclerViewAdapter

ItemClick在这里打电话

DayAdapter.java

holder.setItemClickListener(new ItemClickListener() {
        @Override
        public void onClick(View view, int position, boolean isLongClick) {
            openProgramActivity(view, position);
        }
    });
}

此功能打开一个新的Activity

public void openProgramActivity(View view, int position) {
    //Intent openProgramActivity = new Intent(context, ProgramActivity.class);
    Intent openProgramActivity = new Intent(view.getContext(), ProgramActivity.class);
    openProgramActivity.putExtra("index",position);
    view.getContext().startActivity(openProgramActivity);
}

FragmentDay30.java

public class FragmentDay30 extends Fragment {

private View view;

public static FragmentDay30 newInstance() {
    FragmentDay30 fragment = new FragmentDay30();
    Bundle args = new Bundle();
    fragment.setArguments(args);
    return fragment;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

    view = inflater.inflate(R.layout.fragment_30day, container,false);

    ViewPager slideViewPager = (ViewPager) view.findViewById(R.id.slideViewPager);
    SlideAdapter slideAdapter = new SlideAdapter(getActivity());
    slideViewPager.setAdapter(slideAdapter);

    RecyclerView fragment30datRecyclerView = (RecyclerView) view.findViewById(R.id.fragment30dayRecyclerView);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);
    fragment30datRecyclerView.setLayoutManager(linearLayoutManager);
    DayAdapter dayAdapter = new DayAdapter(getActivity());
    fragment30datRecyclerView.setAdapter(dayAdapter);

    return view;
}

我尝试用getActvity()getContext()而不是新的Activity

Gursewak Singh |

像这样将contaxt传递给recyclerview适配器构造函数

Context context;
MyAdapter(Context context, .....){
this.context=context;
}

通话活动

context.startActivity(......);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从活动通知片段中的适配器?

片段的ViewPager中的Listview适配器-如何获取活动

如何在片段中调用RecyclerView适配器的方法

如何在适配器中启动活动

从RecyclerView适配器更新活动视图或片段视图

Jetpack导航:如何从recyclerview适配器打开新片段?

如何从片段验证recyclerview适配器TextInputEditText?

如何从Recyclerview适配器的片段之间传递数据

如何从 recyclerview 适配器关闭对话框片段

RecyclerView:未连接适配器;跳过片段中的布局

从活动中获取数据到RecyclerView适配器中?

非活动类或RecyclerView适配器类中的SharedPreference

如何使用RecyclerView在适配器中设置setOnClickListener以显示片段内部

从适配器RecyclerView打开片段

从recyclerView适配器调用片段

从片段通知RecyclerView适配器

如何在Recyclerview适配器中扩展活动的上下文

如何从recyclerview适配器类更改主要活动中的textview文本

如何从适配器到Android Kotlin recyclerview中的活动获取变量值?

从 recyclerview 适配器开始新活动

如何在回收器适配器中添加片段?

如何在片段中声明适配器?

如何从 Kotlin 中的适配器调用片段的函数?

如何从 MainActivity 获取在其他活动中启动的对象的适配器(或实际将数据传输到适配器)?

如何从Java中的适配器刷新活动

如何从Kotlin中的适配器打开活动

如何在活动中更新适配器的文本视图

如何在不获取空指针异常的情况下从活动片段中获取适配器?

如何从适配器调用片段