Как открыть новое действие, щелкнув по элементу в обзоре переработчика. Нажмите на курсы в структуре RecyclerView. Подробная информация о курсе будет отображаться на следующей странице. Я хочу открыть страницы с различной информацией для каждого пункта переработки.
--- RecyclerActivity.java
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setConten``tView(R.layout.lessons_layout);
recyclerView=findViewById(R.id.recyclerview);
MyAdapter myAdapter=new
MyAdapter(RecylerActivity.this,Lesson.getdata());
recyclerView.setAdapter(myAdapter);
LinearLayoutManager linearLayoutManager=new
LinearLayoutManager(RecylerActivity.this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(linearLayoutManager);
}
- MyAdapter.java
public MyAdapter(Context context,ArrayList<Lesson> data){
this.data = data;
inflater=LayoutInflater.from(context);
this.mDataList=data;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View v=inflater.inflate(R.layout.list_item,viewGroup,false);
MyViewHolder holder=new MyViewHolder(v);
return holder;
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
Lesson ClickedLesson=mDataList.get(i);
myViewHolder.setData(ClickedLesson,i);
}
@Override
public int getItemCount() {
return mDataList.size();
}
class MyViewHolder extends RecyclerView.ViewHolder{
TextView mLessonName,mLessonPoint;
RelativeLayout rel;
public MyViewHolder(@NonNull final View itemView) {
super(itemView);
mLessonName=(TextView)itemView.findViewById(R.id.tvLessonName);
mLessonPoint=(TextView)itemView.findViewById(R.id.tvLessonPoint);
rel=(RelativeLayout)itemView.findViewById(R.id.Rellayout);
}
public void setData(Lesson ClickedLesson,int i){
this.mLessonName.setText(ClickedLesson.getLessonname());
this.mLessonPoint.setText(ClickedLesson.getPoint());
}
}
- Lesson.Java
public Lesson() {
}
public Lesson(String lessonname,String point) {
this.lessonname=lessonname;
this.point=point;
}
public String getLessonname() {
return lessonname;
}
public String getPoint() {
return point;
}
public void setLessonname(String lessonname) {
this.lessonname = lessonname;
}
public void setPoint(String point) {
this.point = point;
}
public static ArrayList<Lesson> getdata(){
ArrayList<Lesson> dataList=new ArrayList<Lesson>();
Lesson tmp=new Lesson();
tmp.setLessonname("Matematik");
tmp.setPoint("BA");
dataList.add(tmp);
Lesson tmp2=new Lesson();
tmp2.setLessonname("Mobil programlama");
tmp2.setPoint("AA");
dataList.add(tmp2);
Lesson tmp3=new Lesson();
tmp3.setLessonname("Algoritma");
tmp3.setPoint("BB");
dataList.add(tmp3);
Lesson tmp4=new Lesson();
tmp4.setLessonname("İngilizce");
tmp4.setPoint("DC");
dataList.add(tmp4);
Lesson tmp5=new Lesson();
tmp5.setLessonname("Yapay zeka");
tmp5.setPoint("CC");
dataList.add(tmp5);
return dataList;
}
- list_item.xml
<RelativeLayout
android:id="@+id/Rellayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cardview_shadow_end_color"
android:clickable="true"
android:orientation="horizontal">
<TextView
android:id="@+id/tvLessonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ders"
android:textSize="25sp"
android:textStyle="bold"
android:layout_margin="7dp"/>
<TextView
android:id="@+id/tvLessonPoint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not"
android:textSize="20sp"
android:layout_alignParentEnd="true"
android:textStyle="italic"
android:layout_margin="7dp"/>
</RelativeLayout>