### IntStepperView XML Attributes Example
Source: https://context7.com/tonycode/stepper-views/llms.txt
Provides an example of how to use the IntStepperView in an XML layout file, demonstrating the usage of various attributes like `isv_value`, `isv_minValue`, `isv_maxValue`, and `isv_step`.
```xml
```
--------------------------------
### Install StepperViews Library using Gradle
Source: https://context7.com/tonycode/stepper-views/llms.txt
Instructions to add the StepperViews library to your Android project by including the JitPack repository and the dependency in your Gradle build files. This enables the use of StepperViews components in your application.
```kotlin
// settings.gradle.kts or build.gradle.kts (repositories block)
repositories {
google()
mavenCentral()
maven("https://jitpack.io")
}
// app/build.gradle.kts (dependencies block)
dependencies {
implementation("com.github.tonycode:stepper-views:0.1.1")
}
```
--------------------------------
### Configure and Listen to IntStepperView in Kotlin
Source: https://github.com/tonycode/stepper-views/blob/main/README.md
This Kotlin snippet shows how to programmatically configure an IntStepperView and set up a listener for value changes. It covers setting properties like value, min/max, and step, and logging the new value on change.
```kotlin
// configure programmatically
vb.intStepperView1.apply {
value = 0
minValue = -100
maxValue = 100
step = 10
}
// listen to value changes
vb.intStepperView1.onChangeListener = { value: Int ->
Log.d(TAG, "value is $value")
}
```
--------------------------------
### Configure IntStepperView Programmatically in Kotlin
Source: https://context7.com/tonycode/stepper-views/llms.txt
Demonstrates how to programmatically configure an IntStepperView in an Android Activity using Kotlin. Shows setting initial value, min/max bounds, step size, and attaching a listener for value change events.
```kotlin
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import dev.tonycode.stepperviews.IntStepperView
class ProductActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_product)
val quantityStepper = findViewById(R.id.quantityStepper)
// Configure stepper properties
quantityStepper.apply {
value = 1 // Set initial value
minValue = 1 // Minimum allowed value
maxValue = 100 // Maximum allowed value
step = 5 // Increment/decrement by 5
}
// Listen for value changes
quantityStepper.onChangeListener = { newValue: Int ->
Log.d("ProductActivity", "Quantity changed to: $newValue")
updateTotalPrice(newValue)
}
}
private fun updateTotalPrice(quantity: Int) {
val unitPrice = 29.99
val total = unitPrice * quantity
// Update UI with new total
}
}
```
--------------------------------
### Configure IntStepperView in XML
Source: https://github.com/tonycode/stepper-views/blob/main/README.md
This XML snippet demonstrates how to declare and configure an IntStepperView in your Android layout. It shows attributes for setting initial value, min/max values, and step increment.
```xml
```
--------------------------------
### IntStepperView View Binding Usage in Kotlin
Source: https://context7.com/tonycode/stepper-views/llms.txt
Demonstrates using View Binding to access and configure IntStepperView components within an Android Activity. It shows how to set initial values, min/max ranges, step sizes, and define change listeners for temperature and volume steppers.
```kotlin
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.example.app.databinding.ActivitySettingsBinding
class SettingsActivity : AppCompatActivity() {
private lateinit var binding: ActivitySettingsBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root)
// Configure temperature stepper (-20 to 40 degrees, step by 1)
binding.temperatureStepper.apply {
value = 22
minValue = -20
maxValue = 40
step = 1
onChangeListener = { temp ->
Log.d("Settings", "Temperature set to: $temp°C")
binding.temperatureDisplay.text = "$temp°C"
}
}
// Configure volume stepper (0 to 100, step by 10)
binding.volumeStepper.apply {
value = 50
minValue = 0
maxValue = 100
step = 10
onChangeListener = { volume ->
Log.d("Settings", "Volume set to: $volume%")
updateVolumeIcon(volume)
}
}
}
private fun updateVolumeIcon(volume: Int) {
binding.volumeIcon.setImageResource(
when {
volume == 0 -> R.drawable.ic_volume_off
volume < 50 -> R.drawable.ic_volume_low
else -> R.drawable.ic_volume_high
}
)
}
}
```
--------------------------------
### IntStepperView Dynamic Property Updates in Kotlin
Source: https://context7.com/tonycode/stepper-views/llms.txt
Illustrates how to dynamically update properties of an IntStepperView at runtime in an Android Activity. This includes changing the step size, modifying the minimum and maximum value bounds, and reading the current value.
```kotlin
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import dev.tonycode.stepperviews.IntStepperView
class DynamicStepperActivity : AppCompatActivity() {
private lateinit var priceStepper: IntStepperView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dynamic)
priceStepper = findViewById(R.id.priceStepper)
// Initial configuration
priceStepper.apply {
value = 100
minValue = 0
maxValue = 1000
step = 10
}
// Change step size based on user preference
findViewById