Good day! I have a news list for which the adapter was created
public class NewsFeedRecyclerViewAdapter extends RecyclerView.Adapter<NewsFeedRecyclerViewAdapter.ViewHolder> { private List<News> mItems; private Context mContext; private NewsFeedRecyclerViewAdapter.OnItemClickListener onItemClickListener; public NewsFeedRecyclerViewAdapter(Context context, List<News> items) { mItems = items; mContext = context; } @Override public long getItemId(int position) { return position; ^ Here is the method of getting the position of 1 news item, which returns a value in long format.
I also have a separate News class, all data template:
public class News extends RealmObject { @SerializedName("id") @PrimaryKey private long mId; public long getId() { return mId; } public void setId(long mId) { this.mId = mId; } ^ It is spelled id 1 news;
And now, dear experts, the question! :) How do I in a separate fragment with detailed information of this very 1 news to register correctly intent. It is necessary that he take the position from the adapter and save the id from the News class.
This is what my inquiring mind is capable of:
mAdapter = new NewsFeedRecyclerViewAdapter(getActivity(), strings); mAdapter.setOnItemClickListener((view, position) -> { Intent intent = new Intent(getActivity(), DetailNewsActivity.class); News news = (News) mAdapter.getItemId(position); intent.putExtra("id", news.getId()); getActivity().startActivity(intent); }); Tell me what to do?
