Я создаю фитнес-приложение, в котором пользователю разрешено создавать свой собственный список тренировок, и они могут сделать это, нажав кнопку «+» рядом с изображением. один щелчок, imageview, textview1 и textview2 должны быть добавлены в список при следующем действии. в основном, когда кнопка нажата, данные должны быть добавлены в UserCustomiseWorkout, который имеет список
AllExercise Java
public class AllExercises extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_exercises);
ImageButton imagebutton7 = (ImageButton) findViewById(R.id.imageButton7);
imagebutton7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), UserCustomiseWorkout.class);
startActivity(intent);
}
});
}
public void clickNextExPage(View v)
{
Intent nextpage = new Intent(this, AllExercises2.class);
startActivity(nextpage);
}
AllExercise XML
'' '
<ScrollView 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AllExercises">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView11"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="80dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/bicyclecrunch" />
<ImageView
android:id="@+id/imageView12"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="51dp"
android:layout_marginLeft="51dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="80dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/imageView11"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/catpose" />
<ImageView
android:id="@+id/imageView13"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="80dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="30dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView11"
app:srcCompat="@drawable/chairpose" />
<ImageView
android:id="@+id/imageView14"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="51dp"
android:layout_marginLeft="51dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="80dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView13"
app:layout_constraintTop_toBottomOf="@+id/imageView12"
app:srcCompat="@drawable/childspose" />
<ImageView
android:id="@+id/imageView15"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="80dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="30dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView13"
app:srcCompat="@drawable/cobblerpose" />
<ImageView
android:id="@+id/imageView16"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="51dp"
android:layout_marginLeft="51dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="80dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView15"
app:layout_constraintTop_toBottomOf="@+id/imageView14"
app:srcCompat="@drawable/cobrapushup" />
<ImageView
android:id="@+id/imageView17"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="80dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="30dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView15"
app:srcCompat="@drawable/crunches" />
<ImageView
android:id="@+id/imageView18"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="51dp"
android:layout_marginLeft="51dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="80dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView17"
app:layout_constraintTop_toBottomOf="@+id/imageView16"
app:srcCompat="@drawable/doubleleglifts" />
<ImageView
android:id="@+id/imageView19"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="80dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="30dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView17"
app:srcCompat="@drawable/downwarddogpose" />
<ImageView
android:id="@+id/imageView20"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="51dp"
android:layout_marginLeft="51dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="80dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView19"
app:layout_constraintTop_toBottomOf="@+id/imageView18"
app:srcCompat="@drawable/glutebridge" />
<ImageButton
android:id="@+id/imageButton7"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="152dp"
android:layout_marginLeft="152dp"
android:layout_marginBottom="12dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/imageView13"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/more" />
<ImageButton
android:id="@+id/imageButton8"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="152dp"
android:layout_marginLeft="152dp"
android:layout_marginBottom="16dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/imageView15"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/more" />
<ImageButton
android:id="@+id/imageButton9"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="152dp"
android:layout_marginLeft="152dp"
android:layout_marginBottom="16dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/imageView17"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/more" />
<ImageButton
android:id="@+id/imageButton10"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="152dp"
android:layout_marginLeft="152dp"
android:layout_marginBottom="16dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/imageView19"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/more" />
<ImageButton
android:id="@+id/imageButton11"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="152dp"
android:layout_marginLeft="152dp"
android:layout_marginBottom="64dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/more" />
<ImageButton
android:id="@+id/imageButton21"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="58dp"
android:layout_marginRight="58dp"
android:layout_marginBottom="16dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/imageView14"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/more" />
<ImageButton
android:id="@+id/imageButton22"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="58dp"
android:layout_marginRight="58dp"
android:layout_marginBottom="16dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/imageView16"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/more" />
<ImageButton
android:id="@+id/imageButton23"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="58dp"
android:layout_marginRight="58dp"
android:layout_marginBottom="16dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/imageView18"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/more" />
<ImageButton
android:id="@+id/imageButton24"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="58dp"
android:layout_marginRight="58dp"
android:layout_marginBottom="16dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/imageView20"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/more" />
<ImageButton
android:id="@+id/imageButton25"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="56dp"
android:layout_marginRight="56dp"
android:layout_marginBottom="68dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/more" />
<Button
android:id="@+id/next_ex_page"
android:layout_width="150dp"
android:layout_height="45dp"
android:layout_marginTop="40dp"
android:onClick="clickNextExPage"
android:text="Next Page"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView19" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> '''
UserCustomiseWorkout Java
public class UserCustomiseWorkout extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_customise_workout);
}
UserCustomiseWorkout XML
''' <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView31"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="@+id/linearLayout7"
app:layout_constraintEnd_toStartOf="@+id/linearLayout7"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/linearLayout7"
app:layout_constraintVertical_bias="0.0"
tools:srcCompat="@tools:sample/avatars" />
<LinearLayout
android:id="@+id/linearLayout7"
android:layout_width="313dp"
android:layout_height="100dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView31"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textView39"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginLeft="10dp"
android:layout_marginTop="25dp"
android:textSize="20sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/textView40"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> '''