I am making an android application using java and xml, the application allows to debate by generating arguments and counter arguments. To display the argument list create an "external" recyclerview that inflates a view which contains linear layout. To display the list of counter arguments create an internal recyclerview that inflates a view which contains a cardview which allows counterarguments on a specific argument. The problem is that the internal recyclerview does not show the complete list of counterarguments. I leave you part of my code hoping that you can help me
adapterArgument.class
public class adapterArguments extends RecyclerView.Adapter<adapterArguments.ViewHolder> {
private List<ListArguments> data;
private LayoutInflater inflater;
private Context context;
public String position_selected;
public static String argument;
public adapterArguments(List<ListArguments> itemList, Context context) {
this.data = itemList;
this.inflater = LayoutInflater.from(context);
this.context = context;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.compontents_arguments_recyclerview,null);
return new adapterArguments.ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
ConexionSQliteHelper conn=new ConexionSQliteHelper(context,"db_testwuad_7",null,31);
holder.arguments.setText(data.get(position).getArguments());
holder.name_user.setText(data.get(position).getName_user());
holder.date.setText(data.get(position).getDate_arguments());
holder.position.setText(data.get(position).getPosition());
int id_argument_selected = data.get(position).getId();
position_selected = holder.position.getText().toString();
holder.list_contrarguments = conn.getContrarguments(id_argument_selected);
holder.recyclerView_contrarguments.setLayoutManager(new LinearLayoutManager(context));
holder.recyclerView_contrarguments.setHasFixedSize(true);
holder.listContrarguments = new adapterContrarguments(holder.list_contrarguments,context);
holder.recyclerView_contrarguments.setAdapter(holder.listContrarguments);
final int[] checkedItem = {-1};
if(position_selected.equals("A favor")){
holder.position.setBackgroundColor(Color.parseColor("#073FD7"));
}
else{
holder.position.setBackgroundColor(Color.parseColor("#FC0C1E"));
}
holder.addContrarguments.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(v.getContext());
alertDialog.setTitle("Añadir un Contrargumento");
alertDialog.setMessage("¿Quieres añadir un contrargumento a este texto?");
alertDialog.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
argument = holder.arguments.getText().toString();
contrargument fragment = new contrargument();
Bundle args = new Bundle();
args.putString("argument", argument);
args.putInt("id",id_argument_selected);
fragment.setArguments(args);
FragmentManager fragmentManager;
FragmentTransaction fragmentTransaction;
fragmentManager = ((AppCompatActivity)context).getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
alertDialog.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog customAlertDialog = alertDialog.create();
customAlertDialog.show();
}
});
holder.deleteDiscuss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(v.getContext());
alertDialog.setTitle("¿Deseas eliminar este argumento?");
alertDialog.setMessage("¿Quieres añadir un contrargumento a este texto?");
alertDialog.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
boolean user_create_debate = conn.verifyCreatorDebate(holder.name_user.getText().toString());
Toast.makeText(context, "el valor es"+user_create_debate, Toast.LENGTH_SHORT).show();
if(user_create_debate){
conn.deleteArgument(id_argument_selected);
}
else{
Toast.makeText(context, "No puede eliminar el argumento,ya que no es el creador del texto", Toast.LENGTH_SHORT).show();
}
opinionUserOnPostDebate fragment = new opinionUserOnPostDebate();
FragmentManager fragmentManager;
FragmentTransaction fragmentTransaction;
fragmentManager = ((AppCompatActivity)context).getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.detach(fragment).attach(fragment).commit();
}
});
alertDialog.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog customAlertDialog = alertDialog.create();
customAlertDialog.show();
}
});
holder.changePosition.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle("Cambio de postura");
final String[] listItems = new String[]{"Cambie de opinión","Me equivoque de botón","Otro"};
alertDialog.setSingleChoiceItems(listItems, checkedItem[0], new DialogInterface.OnClickListener() {
@SuppressLint("SetTextI18n")
@Override
public void onClick(DialogInterface dialog, int which) {
checkedItem[0] = which;
}
});
alertDialog.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(position_selected.equals("A favor")){
//conn.changePosition(id_argument_selected,"En contra");
}
else{
//conn.changePosition(id_argument_selected,"A favor");
}
}
});
alertDialog.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog customAlertDialog = alertDialog.create();
customAlertDialog.show();
}
});
holder.Report.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle("Reportar post");
final String[] listItems = new String[]{"Opinión contiene lenguaje ofensivo","Opinión contiene información personal","Otro"};
alertDialog.setSingleChoiceItems(listItems, checkedItem[0], new DialogInterface.OnClickListener() {
@SuppressLint("SetTextI18n")
@Override
public void onClick(DialogInterface dialog, int which) {
checkedItem[0] = which;
}
});
alertDialog.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(position_selected.equals("A favor")){
//conn.changePosition(id_argument_selected,"En contra");
}
else{
//conn.changePosition(id_argument_selected,"A favor");
}
}
});
alertDialog.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog customAlertDialog = alertDialog.create();
customAlertDialog.show();
}
});
}
@Override
public int getItemCount() {
return data.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView arguments,name_user,date,position;
ImageButton addContrarguments,deleteDiscuss,addFriend,changePosition,Report;
List<ListContrarguments> list_contrarguments;
RecyclerView recyclerView_contrarguments;
public adapterContrarguments listContrarguments;
public ViewHolder(@NonNull View itemView) {
super(itemView);
arguments = itemView.findViewById(R.id.arguments_posted);
name_user = itemView.findViewById(R.id.name_arguments);
date = itemView.findViewById(R.id.date_arguments);
position = itemView.findViewById(R.id.position);
addContrarguments = itemView.findViewById(R.id.comments);
deleteDiscuss = itemView.findViewById(R.id.delete);
changePosition = itemView.findViewById(R.id.change_position);
addFriend = itemView.findViewById(R.id.add_friend);
Report = itemView.findViewById(R.id.report_argument);
recyclerView_contrarguments = itemView.findViewById(R.id.recycler_contrargument);
}
}
}
layout.compontents_arguments_recyclerview.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal">
<TextView
android:id="@+id/position"
android:textColor="@color/white"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textStyle="bold"
android:textSize="25dp"
android:background="#0AA842">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/image_person_contrarguments"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp"
android:layout_marginRight="5dp">
</ImageView>
<TextView
android:id="@+id/name_arguments"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="15dp"
android:textSize="14sp"
>
</TextView>
<TextView
android:id="@+id/date_arguments"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
>
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="360dp"
android:orientation="vertical"
>
<TextView
android:id="@+id/arguments_posted"
android:layout_width="match_parent"
android:layout_height="140dp"
>
</TextView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#FEFEFE"
>
<ImageButton
android:id="@+id/comments"
android:layout_width="60dp"
android:layout_height="match_parent"
android:src="@drawable/add_comments"
android:background="#FEFEFE"
android:layout_marginLeft="50dp"
>
</ImageButton>
<ImageButton
android:id="@+id/delete"
android:layout_width="60dp"
android:layout_height="match_parent"
android:src="@drawable/delete"
android:background="#FEFEFE"
>
</ImageButton>
<ImageButton
android:id="@+id/change_position"
android:layout_width="60dp"
android:layout_height="match_parent"
android:src="@drawable/change_opinion"
android:background="#FEFEFE"
>
</ImageButton>
<ImageButton
android:id="@+id/add_friend"
android:layout_width="60dp"
android:layout_height="match_parent"
android:src="@drawable/add_friend"
android:background="#FEFEFE"
>
</ImageButton>
<ImageButton
android:id="@+id/report_argument"
android:layout_width="60dp"
android:layout_height="match_parent"
android:src="@drawable/display_report"
android:background="#FEFEFE"
>
</ImageButton>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#A4A1A1"
>
</View>
<include
android:layout_width="match_parent"
android:layout_height="179dp"
layout="@layout/recyclerview_contrarguments"
>
</include>
</LinearLayout>
</LinearLayout>
</LinearLayout>
adapterContrarguments.class
public class adapterContrarguments extends RecyclerView.Adapter<adapterContrarguments.ViewHolder> {
private List<ListContrarguments> data;
private LayoutInflater inflater;
private Context context;
public adapterContrarguments(List<ListContrarguments> itemlist, Context context) {
this.data = itemlist;
this.inflater = LayoutInflater.from(context);
this.context = context;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.cardview_contrarguments,null);
return new adapterContrarguments.ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.name_user_posted_contrarguments.setText(data.get(position).getName_user_posted_contrarguments());
holder.contrarguments.setText(data.get(position).getPost_contrarguments());
holder.date_contrarguments.setText(data.get(position).getDate_contrarguments());
}
@Override
public int getItemCount() {
return data.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView name_user_posted_contrarguments,date_contrarguments,contrarguments;
public ViewHolder(@NonNull View itemView) {
super(itemView);
name_user_posted_contrarguments = itemView.findViewById(R.id.user_post_contrargument);
date_contrarguments = itemView.findViewById(R.id.date_contrargument);
contrarguments = itemView.findViewById(R.id.contrargument_post);
}
}
}
cardview_contrarguments.xml
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
app:cardCornerRadius="20dp"
app:cardElevation="4dp"
app:cardUseCompatPadding="true"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="395dp"
android:layout_height="200dp"
android:padding="26dp">
<TextView
android:id="@+id/user_post_contrargument"
android:layout_width="168dp"
android:layout_height="19dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/contrargument_post"
android:layout_width="336dp"
android:layout_height="115dp"
android:ems="10"
android:gravity="start|top"
android:inputType="textMultiLine"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.493"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:ignore="SpeakableTextPresentCheck" />
<TextView
android:id="@+id/date_contrargument"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.89"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.022" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>