Skip to content

Commit

Permalink
feat: add button to kotlin example to send custom event (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyang1520 authored Jun 25, 2022
1 parent d0dfb15 commit 5c1e573
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.amplitude.android.sample

import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.amplitude.core.events.EventOptions
import com.amplitude.core.events.Identify
Expand All @@ -14,6 +15,8 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val sendEventButton: Button = findViewById(R.id.button)

// set user properties
val identify = Identify()
identify.set("user-platform", "android")
Expand Down Expand Up @@ -41,6 +44,8 @@ class MainActivity : AppCompatActivity() {
amplitude.revenue(revenue)

// track event with event properties
amplitude.track("test event properties", mapOf("test" to "test event property value"), options)
sendEventButton.setOnClickListener {
amplitude.track("test event properties", mapOf("test" to "test event property value"), options)
}
}
}
10 changes: 10 additions & 0 deletions samples/kotlin-android-app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Kotlin Android example!"
Expand All @@ -15,4 +16,13 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Event"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 5c1e573

Please sign in to comment.