I have an activity where there are ImageView
s as items in a ScrolView
, this list will grow as time goes. What I want to do is when I swipe right on an item (imageView) it should navigate to another activity (let's say, orderActivity
) where I can take further action. TextViews on orderActivity
to be populated (details like, name of the item, price, quantity, etc) based on the item that is swiped right.
Following is the XML code, I don't have any idea how to code for the swipe right.
Is this the way it should be done, or is there a better way?
<?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"
tools:context=".ListOfItems">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="6dp"
tools:layout_editor_absoluteY="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/iVitemOne"
android:layout_width="match_parent"
android:layout_height="103dp"
android:layout_marginTop="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/item1" />
<ImageView
android:id="@+id/iVitemTwo"
android:layout_width="match_parent"
android:layout_height="103dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iVitemOne"
app:srcCompat="@drawable/item2" />
<ImageView
android:id="@+id/iVitemThree"
android:layout_width="match_parent"
android:layout_height="103dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iVitemTwo"
app:srcCompat="@drawable/item3" />
<ImageView
android:id="@+id/iVitemFour"
android:layout_width="match_parent"
android:layout_height="103dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iVitemThree"
app:srcCompat="@drawable/item4" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
I am on Android Studio using Kotlin.
Edit:
I added the Override part into the ListOfItems.kt file as follows. I know it's wrong.
class ListOfGames : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_list_of_games)
}
imageview.setOnTouchListener(object :OnSwipeTouchListener(context){
override fun onSwipeRight() {
//Do want you want
}
})
}