public class RecycleViewAdapter extends RecyclerView.Adapter<RecycleViewAdapter.ViewHolder>{
private static final String TAG = "RecycleViewAdapter";
private ArrayList<String> mImageNames = new ArrayList<>();
private ArrayList<String> mImages = new ArrayList<>();
private Context mContext;
public RecycleViewAdapter (Context mContext, ArrayList<String> mImageNames, ArrayList<String> mImages) {
this.mImageNames = mImageNames;
this.mImages = mImages;
this.mContext = mContext;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder (@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.material, parent, false);
ViewHolder holder = new ViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder (@NonNull ViewHolder holder, final int position) {
Log.d(TAG, "onBindViewHolder: called.");
Glide.with(mContext)
.asBitmap()
.load(mImages.get(position))
.into(holder.image1);
holder.image_name.setText(mImageNames.get(position));
holder.parent_layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View view) {
Log.d(TAG, "onClick: clicked on " + mImageNames.get(position));
Toast.makeText(mContext, mImageNames.get(position), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public int getItemCount () {
return mImageNames.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder{
ImageView image1;
TextView image_name;
RelativeLayout parent_layout;
public ViewHolder (@NonNull View itemView) {
super(itemView);
image1 = itemView.findViewById(R.id.image1);
image_name = itemView.findViewById(R.id.image_name);
parent_layout = itemView.findViewById(R.id.parent_layout);
}
}
}
public class Material extends AppCompatActivity {
private static final String TAG = "Material";
private ArrayList<String> mNames = new ArrayList<>();
private ArrayList<String> mImageUrls = new ArrayList<>();
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.materials);
Log.d(TAG, "onCreate: started.");
initImageBitmaps();
}
private void initImageBitmaps(){
Log.d(TAG, "initImageBitmaps: preparing bitmaps");
//1
mImageUrls.add("https://www.wallpaperup.com/uploads/wallpapers/2015/01/17/589833/ae71f6d11c0ad38688daa0e17dd9b8be.jpg");
mNames.add("Біологічна та загальна хімія");
//2
mImageUrls.add("https://ukrinnovate.com/upload/website-science-or-innovation-article-image-201803191200.jpg");
mNames.add("Гістологія");
//3
mImageUrls.add("https://i.ytimg.com/vi/36spQsZ5pqQ/maxresdefault.jpg");
mNames.add("Загальної гігієна та екологія");
//4
mImageUrls.add("https://images.wallpaperscraft.ru/image/kletki_mikrobiologiya_struktura_113059_1920x1080.jpg");
mNames.add("Мікробіологія");
initRecyclerView();
}
private void initRecyclerView(){
Log.d(TAG, "initRecyclerView: init recycleview.");
RecyclerView recyclerView = findViewById(R.id.recyclerv_view);
RecycleViewAdapter adapter = new RecycleViewAdapter(this, mNames, mImageUrls);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
}
Использую RecycleView хочу что бы для каждого элемента было отдельное окно экрана.Но не могу понять как это можно реализовать в данном коде.