I have a recyclerview with 10 items and when I click it opens an activity detail for each one of them. What is the best method to create an Activity details for each item? The xml of the activity detail is the same for all only the content of the Textview and the content of the imageview change. Is there any way to use a single activity detail and to change the content according to the selected item? Since at this moment I have created 10 activity details.
"Excuse me, I think it does not explain me well, the only thing shared by the items in the recyclerview and the activity detail is the image through a shared transition, all the content of the text view are different. that the detail actyvities for each item share the same xml, and change the information depending on the selected item, therefore there is a way, and there is sure to be, to create only one activity detail that shares the image and changes the contents of its text view depending on the selected item, thank you very much for your patience. "
I leave the xml of the actyviti detail (for example the one of statics) and of the item that is used in the recyclerview, you will see how the only thing that is shared is the imageview since they share the transition name.
I'm a rookie.
Thanks
static class Item1Holder extends RecyclerView.ViewHolder{
public final TextView nombre, text;
public final ImageView imagen;
public Item1Holder(View itemView) {
super(itemView);
nombre= (TextView)itemView.findViewById(R.id.textView90);
imagen=(ImageView)itemView.findViewById(imageView2);
text=(TextView)itemView.findViewById(R.id.textView91);
itemView.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = null;
switch (getAdapterPosition()) {
case 0:
intent = new Intent(context, MruyMruv.class);
break;
case 1:
intent = new Intent(context, TVerticalyCLibre.class);
break;
case 2:
intent = new Intent(context, TOblicuo.class);
break;
case 3:
intent = new Intent(context, MCUyMCUV.class);
break;
case 4:
intent = new Intent(context, Dinamica.class);
break;
case 5:
intent = new Intent(context, MGravitatorio.class);
break;
case 6:
intent = new Intent(context, FElastica.class);
break;
case 7:
intent = new Intent(context, MOS.class);
break;
case 8:
intent = new Intent(context, Estatica.class);
break;
case 9:
intent = new Intent(context, PenduloSimple.class);
break;
case 10:
intent = new Intent(context, Hidroestatica.class);
break;
}
ActivityOptionsCompat option = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) context, imagen, context.getString(R.string.image_transition));
context.startActivity(intent, option.toBundle());
((Activity) context).getWindow().setExitTransition(TransitionInflater.from(context).inflateTransition(R.transition.shared_element_exit));
}
});
}
static actyviti xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="20dp"
app:cardElevation="8dp">
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
android:src="@drawable/estaticamenor"
android:transitionName="@string/image_transition" />
</android.support.v7.widget.CardView>
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
tools:layout_conversion_absoluteWidth="384dp"
tools:layout_conversion_absoluteHeight="72dp"
android:layout_width="match_parent"
android:layout_height="300dp">
</include>
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="@+id/card20"
android:layout_marginTop="20dp"
android:layout_marginRight="12dp"
android:layout_marginLeft="12dp"
xmlns:android="http://schemas.android.com/apk/res/android"
app:cardElevation="4dp"
app:cardCornerRadius="0dp"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:scrollbars="none"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="@string/Estatica"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textStyle="bold"
android:layout_alignParentStart="true"
android:layout_marginTop="160dp"/>
</RelativeLayout>
</ScrollView>
</android.support.v7.widget.CardView>
Item xml (row)
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="1dp"
android:layout_marginStart="70dp"
android:elevation="7dp">
<TextView
android:id="@+id/textView90"
android:layout_width="match_parent"
android:layout_height="200dp"
android:gravity="center"
android:layout_marginBottom="30dp"
android:shadowColor="#212121"
android:shadowDx="-8"
android:shadowDy="1"
android:shadowRadius="10"
android:text="TextView2"
android:textColor="#fafafa"
android:textSize="48sp"
android:textStyle="bold" />
</RelativeLayout>
<android.support.v7.widget.CardView
android:id="@+id/card1"
android:layout_width="370dp"
android:layout_height="440dp"
android:layout_marginStart="2dp"
android:layout_marginEnd="40dp"
android:layout_marginTop="50dp"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="#455a64"
app:cardCornerRadius="3dp"
app:cardElevation="4dp"
android:layout_centerHorizontal="true">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card2"
android:layout_width="315dp"
android:layout_height="150dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="140dp"
app:cardBackgroundColor="#c9cd5c"
app:cardCornerRadius="0dp"
app:cardElevation="6dp">
<TextView
android:id="@+id/textView91"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:gravity="center"
android:text="TextView3"
android:textColor="#eceff1"
android:textSize="12.5sp"
android:textStyle="italic"
android:transitionGroup="false" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/card3"
android:layout_width="300dp"
android:layout_height="280dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="10dp"
android:layout_marginTop="315dp"
android:layout_marginBottom="10dp"
app:cardCornerRadius="0dp"
app:cardElevation="6dp">
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:transitionName="@string/image_transition" />
</android.support.v7.widget.CardView>
<ImageView
android:id="@+id/Image1"
android:layout_width="60dp"
android:layout_height="60dp"
android:elevation="7dp"
android:scaleType="centerCrop"
app:srcCompat="@mipmap/comillas"
android:layout_marginTop="100dp"
android:layout_marginLeft="2dp"/>