gpt4 book ai didi

android - 如何从 fragment 中的 RecyclerView 适配器启动 Activity

转载 作者:行者123 更新时间:2023-11-29 15:35:32 26 4
gpt4 key购买 nike

<分区>

我无法从 RecyclerViewAdapter 单击 RecyclerView 到新的 Activity

我在这里调用 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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com