Моя программа предоставляет действие с двумя представлениями карт, которые, в свою очередь, используют одно представление переработчика. Это обучающее приложение, поэтому двухкарточные представления предназначены для Java и HTML, и они используют один и тот же адаптер для представления переработчика. Как в Java, так и в HTML будет страница введения, поэтому я хочу открыть различные действия для введения в Java и введения в HTML
Я пытался различать виды карточек во время щелчка мышью на видах представления переработчика
holder.setItemClickListener(new ItemClickListener() {
@Override
public void onItemClickListener(View v, int position) {
Intent intent;
switch (v.getId()){
case R.id.javacardId :
if (models.get(position).getTitle().equals("Introduction")){
intent = new Intent(c,anotherActivity.class);
c.startActivity(intent);
}
break;
case R.id.htmlcardId :
if (models.get(position).getTitle().equals("Introduction")){
intent = new Intent(c,html_Introduction.class);
c.startActivity(intent);
}
break;
}
---java_class for JAVA CardView enabling recycler view
package com.hfad.dashboard_ui;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import java.util.ArrayList;
public class java_prog extends AppCompatActivity {
String name = "java_prog";
RecyclerView contentList;
contentAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_java_prog);
contentList = findViewById(R.id.courseContentList);
contentList.setLayoutManager(new LinearLayoutManager(this));
adapter = new contentAdapter(this, getList());
contentList.setAdapter(adapter);
}
private ArrayList<model> getList(){
ArrayList<model> models = new ArrayList<>();
model m = new model();
m.setTitle("Introduction");
m.setImage(R.raw.intro);
models.add(m);
m = new model();
m.setTitle("Arrays");
m.setImage(R.raw.array);
models.add(m);
m = new model();
m.setTitle("Classes and Objects");
m.setImage(R.raw.objects);
models.add(m);
m = new model();
m.setTitle("Loops");
m.setImage(R.raw.loop);
models.add(m);
m = new model();
m.setTitle("Exception");
m.setImage(R.raw.exception);
models.add(m);
return models;
}
}
---
--- html class for HTML CardView enabling recycler view
package com.hfad.dashboard_ui;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import java.util.ArrayList;
public class html_prog extends AppCompatActivity {
RecyclerView contentList;
contentAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_html_prog);
contentList = findViewById(R.id.courseContentList);
contentList.setLayoutManager(new LinearLayoutManager(this));
adapter = new contentAdapter(this, getList());
contentList.setAdapter(adapter);
}
private ArrayList<model> getList(){
ArrayList<model> models = new ArrayList<>();
model m = new model();
m.setTitle("Introduction");
m.setImage(R.raw.intro);
models.add(m);
m = new model();
m.setTitle("Arrays");
m.setImage(R.raw.array);
models.add(m);
m = new model();
m.setTitle("Classes and Objects");
m.setImage(R.raw.objects);
models.add(m);
m = new model();
m.setTitle("Loops");
m.setImage(R.raw.loop);
models.add(m);
m = new model();
m.setTitle("Exception");
m.setImage(R.raw.exception);
models.add(m);
return models;
}
}
---
---Adapter class
package com.hfad.dashboard_ui;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
public class contentAdapter extends RecyclerView.Adapter<holder> {
Context c;
ArrayList<model> models;
public contentAdapter(Context c, ArrayList<model> models){
this.c=c;
this.models = models;
}
@NonNull
@Override
public holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.content_cardview,parent,false);
return new holder(view);
}
@Override
public void onBindViewHolder(@NonNull holder holder, int position) {
holder.text.setText(models.get(position).getTitle());
holder.image.setImageResource(models.get(position).getImage());
holder.setItemClickListener(new ItemClickListener() {
@Override
public void onItemClickListener(View v, int position) {
Intent intent;
switch (v.getId()){
case R.id.javacardId :
if (models.get(position).getTitle().equals("Introduction")){
intent = new Intent(c,anotherActivity.class);
c.startActivity(intent);
}
break;
case R.id.htmlcardId :
if (models.get(position).getTitle().equals("Introduction")){
intent = new Intent(c,html_Introduction.class);
c.startActivity(intent);
}
break;
}
}
});
}
@Override
public int getItemCount() {
return models.size();
}
}
Я ожидаю, что выходные данные смогут различать представление представлений Java и HTML о вторичной переработке, чтобы я мог назначать им различные действия