我正在 fragment 中解析 Json 数据。为了查看此 Json 数据,我使用了 RecycleView。在这个 fragment 中,我展示了一些帖子的简短细节。我希望当用户单击 recycleView 时,它将转到另一个 Activity 并显示这篇文章的详细信息。如何使我的 RecycleView 可点击?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_recent_post, container, false);
recentpostRecycleView = (RecyclerView) view.findViewById(R.id.recent_posts);
recentpostRecycleView.setLayoutManager(new LinearLayoutManager(getActivity()));
recentPostAdapter = new RecentPostAdapter(getActivity());
recentpostRecycleView.setAdapter(recentPostAdapter);
sendJsonRequest();
return view;
}
我的 RecycleView 截图:
最佳答案
您不应该让 RecyclerView 可点击,而应该让它的卡片可点击。只需添加 android:clickable="true"
到卡片布局,然后将 ClickListener 添加到 ChildViews。如果你对此感到困惑,slidenerd 有一个关于 RecyclerViews 的很好的教程:https://www.youtube.com/watch?v=zE1E1HOK_E4
关于android - 如何使 fragment 中的 RecyclerView 可点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32098445/