0
RecyclerViewデータをフラグメントに渡す方法と、フラグメントにどのコードを渡す必要がありますか。このコードはアクティビティで動作しますが、私は解決策を見たことがありますが、それで私のために働くことはできません。 、putExtras関数にあなたが持っているアクティビティに任意のバンドルを通過させるためのRecyclerViewの値をフラグメントに渡す
@Override
public void onClick(View view) {
Bundle bundle = new Bundle();
int position = getAdapterPosition();
Toast.makeText(context,"this is the position"+position, Toast.LENGTH_SHORT);
bundle.putSerializable("DATA", data.get(getAdapterPosition()));
YourFragmentName f = new YourFragmentName();
f.setArguments(bundle);
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.your_container_frame_layout,
f).commit();
}
に
@Override
public void onClick(View view) {
//Open the new activity (THIS WORKS)
Intent intent = new Intent(context, NotifActivity.class);
Bundle bundle = new Bundle();
int position = getAdapterPosition();
Toast.makeText(context,"this is the position"+position, Toast.LENGTH_SHORT);
bundle.putSerializable("DATA", data.get(getAdapterPosition()));
intent.putExtras(bundle);
context.startActivity(intent);
}
:このコードはrecyclerview
public MyHolder(View itemView) {
super(itemView);
textNotifTitle= (TextView) itemView.findViewById(R.id.textNotifTitle);
textNotifMessage = (TextView) itemView.findViewById(R.id.textNotifMessage);
TextDate = (TextView) itemView.findViewById(R.id.textDate);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
//Open the new activity (THIS WORKS)
Intent intent = new Intent(context, NotifActivity.class);
Bundle bundle = new Bundle();
int position = getAdapterPosition();
Toast.makeText(context,"this is the position"+position, Toast.LENGTH_SHORT);
bundle.putSerializable("DATA", data.get(getAdapterPosition()));
intent.putExtras(bundle);
context.startActivity(intent);
}