グリッドRecyclerView
に画像が1つあります。ユーザーがリサイクルビューをクリックしたときに、リサイクルビューの画像がDetailActivity
に表示されます。リサイクラビューから他のアクティビティへ画像を送信する
これは私のRecyclerAdapterです:
public class AdapterRecyclerDars extends RecyclerView.Adapter<AdapterRecyclerDars.ViewHolder> {
private ArrayList<Modelars> arsha;
private Context context;
//========================================== constructor
public AdapterRecyclerDars(ArrayList<Modelars> arsha, Context context) {
this.arsha = arsha;
this.context = context;
}
//========================================== ViewHolder
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
private TextView txt_grid;
private ImageView img_grid;
public ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
txt_grid = (TextView)itemView.findViewById(R.id.txt_grid);
img_grid = (ImageView)itemView.findViewById(R.id.img_grid);
}
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), DetailActivity.class);
intent.putExtra("img_id",img_grid.getId()); <== I don't know this
v.getContext().startActivity(intent);
}
}
//========================================== onCreateViewHolder
@Override
public AdapterRecyclerDars.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_row, parent, false);
return new ViewHolder(view);
}
//========================================== onBindViewHolder
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
//setText
holder.txt_grid.setText(arsha.get(position).getars_name());
//download image
Glide.with(context).load(arsha.get(position).getars_img()).into(holder.img_grid);
}
//========================================== getItemcount
@Override
public int getItemCount() {
return darsha.size();
}
//==========================================
//==========================================
}
そしてRecyclerViewロードこれが私のフラグメントである:
public class Fragment_one extends Fragment {
ArrayList<Modelars> arsha;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_one, container, false);
RecyclerView recyclerAvalDab = (RecyclerView) view.findViewById(R.id.recycler_frg_aval_dab);
// recyclerAvalDab.setHasFixedSize(true);
initializeData();
RecyclerView.LayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3);
recyclerAvalDab.setLayoutManager(gridLayoutManager);
AdapterRecyclerDars adapterRecyclerDars = new AdapterRecyclerDars(darsha, getActivity());
recyclerAvalDab.setAdapter(adapterRecyclerDars);
return view;
}
private void initializeData() {
arsha = new ArrayList<>();
arsha.add(new Modelars("1", R.drawable.z));
arsha.add(new Modelars("2", R.drawable.s));
arsha.add(new Modelars("3", R.drawable.r));
arsha.add(new Modelars("4", R.drawable.f));
arsha.add(new Modelars("5", R.drawable.a));
arsha.add(new Modelars("6", R.drawable.ad));
arsha.add(new Modelars("7", R.drawable.d));
arsha.add(new Modelars("8", R.drawable.z));
}
}
あなたが – Piyush
piyushやあ、どのようにしている配列[位置]を使用して位置だけを渡す必要がありますか –
さて、私は大丈夫です... – Piyush