I Have Several Problems In Gson Library in (Jetpack Compose) - android

Hello Stackoverflow community
I Would like to fetch data from this Rest Api:
https://adeega.xisaabso.online/Api/android_today_dashboard.php
but unfortunately i have several problems in my application
so how can i solved, i am new in jetpack compose
here are my problems:
No value passed for parameter 'Amaahda'
No value passed for parameter 'Expenses'
No value passed for parameter 'Lacagta_La_dirayo'
No value passed for parameter 'Total'
No value passed for parameter 'Amaahda'
None of the following functions can be called with the arguments supplied
build gradle
implementation("com.android.volley:volley:1.2.1")
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
DashBoardItems Class
package com.example.eee.Classes
data class DashBoardItems(
val Amaahda: Float,
val Expenses: Float,
val Lacagta_La_dirayo: Float,
val Total: Float
)
DashBoardScreen.kt
package com.example.eee.Screens
import android.widget.Toast
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.android.volley.Request
import com.android.volley.Response
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
import com.example.eee.Cards.DashBoardText
import com.example.eee.Classes.DashBoardItems
import com.google.gson.GsonBuilder
#Composable
fun DashBoard_Screen(navController: NavController){
val context = LocalContext.current
val baseUrl = "https://adeega.xisaabso.online/Api/android_last_vouchers.php"
val dashBoardItems_data = DashBoardItems()
val data = remember {
mutableStateOf<DashBoardItems>(DashBoardItems())
}
val stringRequest = StringRequest(baseUrl, { it ->
val gsonBuilder = GsonBuilder()
val gson = gsonBuilder.create()
gson.fromJson(it, DashBoardItems::class.java)
data.value = dashBoardItems_data
}, {
Toast.makeText(context, it.toString(), Toast.LENGTH_SHORT).show()
}).apply {
DashBoardText(data = data.value)
}
val volleyRequest = Volley.newRequestQueue(context)
volleyRequest.add(stringRequest)
}
DashBoardText Composable
package com.example.eee.Cards
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import com.example.eee.Classes.DashBoardItems
#Composable
fun DashBoardText(data: DashBoardItems){
Text(text = data.Total.toString())
Text(text = data.Amaahda.toString())
}

In those two places, you are calling DashBoardItems constructor without any argument, but it requires 4 of them:
val dashBoardItems_data = DashBoardItems()
val data = remember {
mutableStateOf<DashBoardItems>(DashBoardItems())
}
You can call it like DashBoardItems(0F, 0F, 0F, 0F) or specify default values in your constructor:
data class DashBoardItems(
val Amaahda: Float = 0F,
val Expenses: Float = 0F,
val Lacagta_La_dirayo: Float = 0F,
val Total: Float = 0F,
)
Another problem you will soon encounter is that you can't just call api requests from your composables like that, you will need a LaunchedEffect or better a ViewModel.

Related

requestFocus() focuses a TextView, but does not highlight it

I have a Datalogic Memor K – a mobile computer which runs Android 9 and has a hardware keyboard.
In my application, I can move the focus/highlight between controls, including TextView controls with isFocusableInTouchMode = true, manually using the hardware arrow keys (see below).
But when I do it programmatically, requestFocus() returns true, but the TextView does not highlight, although it seems to get the focus, because the next move with the arrow keys starts from it.
I create a project from the Empty activity template.
For better visibility, I add the following to the res/value/themes.xml file:
<!-- Customize your theme here. -->
<item name="android:textSize">25sp</item>
<item name="colorControlHighlight">#color/purple_700</item>
</style>
</resources>
To keep my post shorter, I don't use a layout file and do everything in the code of the main activity:
#file:SuppressLint("SetTextI18n")
package lv.trialto.myapplication
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val numbers = arrayOf("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine")
var nextNumberIndex = 0
val rootLinearLayout = LinearLayout(this).apply {
layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
orientation = LinearLayout.VERTICAL
}
val textViewList = mutableListOf<TextView>()
for (y in 1..3) {
val horizontalLinearLayout = LinearLayout(this).apply {
layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT)
orientation = LinearLayout.HORIZONTAL
}
rootLinearLayout.addView(horizontalLinearLayout)
for (x in 1..3) {
val cell = TextView(this).apply {
width = (100 * context.resources.displayMetrics.density + 0.5).toInt()
isFocusableInTouchMode = true
text = numbers[nextNumberIndex++]
}
textViewList.add(cell)
horizontalLinearLayout.addView(cell)
}
}
rootLinearLayout.addView(Button(this).apply {
layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT)
text = "Focus random cell"
setOnClickListener {
val randomTextView = textViewList[textViewList.indices.random()]
val saveText = randomTextView.text
randomTextView.text = "HERE!"
val result = randomTextView.requestFocus()
Toast.makeText(context, "result = $result", Toast.LENGTH_LONG).show()
lifecycleScope.launch {
delay(1000)
randomTextView.text = saveText
}
}
})
setContentView(rootLinearLayout)
}
}
What am I doing wrong?
Also, what is the correct name of this focus/highlight/cursor?

All intent's extras are null while starting a new activity

This is an application with a list of dogs and information about the dog.
I'm trying to run a DetailActivity that contains information about a dog. It is launched after clicking the Show Details button, which has a setOnClickListener and runs the Intent, passing the name, age, hobby and other parameters of the dog to the running DetailActivity. But when I try to take those parameters in the DetailActivity code, they all equal null.
It's actually very simple and I've done the same thing in google course codelab before (now I decided to practice a bit) and I repeat everything as it's written there, but I don't understand what I'm doing wrong.
I'll insert the DetailActivity and DogCardAdapter code below. You can also see all the code at this link on GitHub: https://github.com/theMagusDev/DogglersApp
DetailActivity.kt:
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.example.dogglers.databinding.ActivityDetailBinding
class DetailActivity() : AppCompatActivity() {
private lateinit var binding: ActivityDetailBinding
private val TAG = "DetailActivity"
companion object {
const val DOG_IMAGE = "dogImage"
const val DOG_NAME = "dogName"
const val DOG_AGE = "dogAge"
const val DOG_HOBBIES = "dogHobbies"
const val DOG_SEX = "dogSex"
}
val dogImageResourceId = intent?.extras?.getString(DOG_IMAGE)
val dogName = intent?.extras?.getString(DOG_NAME)
val dogAge = intent?.extras?.getString(DOG_AGE)
val dogHobbies = intent?.extras?.getString(DOG_HOBBIES)
val dogSex = intent?.extras?.getString(DOG_SEX)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Setup view binding
binding = ActivityDetailBinding.inflate(layoutInflater)
setContentView(binding.root)
val heOrShe: String = when(dogSex){
"male" -> "He"
else -> "She"
}
binding.dogName.text = dogName
Log.d(TAG, "${dogAge.toString()}, ${dogName.toString()}, $dogHobbies, $heOrShe, $dogImageResourceId")
binding.dogDescription.text = getString(R.string.dog_description, dogName, dogAge, dogSex, dogHobbies)
//binding.dogImage.setImageResource(dogImageResourceId!!.toInt())
binding.dogImage.setImageResource(R.drawable.bella)
Log.d(TAG, "dogDescription and dogImage were set")
title = getString(R.string.details_about, dogName)
}
Logcat:
2022-10-02 08:32:25.545 9660-9660/com.example.dogglers D/DetailActivity: null, null, null, She, null
2022-10-02 08:32:25.558 9660-9660/com.example.dogglers D/DetailActivity: dogDescription and dogImage were set
DogCardAdapter.kt:
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.dogglers.DetailActivity
import com.example.dogglers.DetailActivity.Companion.DOG_AGE
import com.example.dogglers.DetailActivity.Companion.DOG_HOBBIES
import com.example.dogglers.DetailActivity.Companion.DOG_IMAGE
import com.example.dogglers.DetailActivity.Companion.DOG_NAME
import com.example.dogglers.DetailActivity.Companion.DOG_SEX
import com.example.dogglers.R
import com.example.dogglers.const.Layout.GRID
import com.example.dogglers.data.DataSource
/**
* Adapter to inflate the appropriate list item layout and populate the view with information
* from the appropriate data source
*/
class DogCardAdapter(
private val context: Context?,
private val layout: Int
): RecyclerView.Adapter<DogCardAdapter.DogCardViewHolder>() {
// Initialize the data using the List found in data/DataSource
val data = DataSource.dogs
/**
* Initialize view elements
*/
class DogCardViewHolder(view: View?): RecyclerView.ViewHolder(view!!) {
// Declare and initialize all of the list item UI components
val imageView: ImageView = view!!.findViewById(R.id.dog_image)
val dogName: TextView = view!!.findViewById(R.id.dog_name)
val dogAge: TextView = view!!.findViewById(R.id.dog_age)
val dogHobbies: TextView = view!!.findViewById(R.id.dog_hobbies)
var dogSex = "n/a"
val showDetailsButton: Button = view!!.findViewById(R.id.details_button)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DogCardViewHolder {
// Use a conditional to determine the layout type and set it accordingly.
// if the layout variable is Layout.GRID the grid list item should be used. Otherwise the
// the vertical/horizontal list item should be used.
val layoutType = when(layout) {
GRID -> R.layout.grid_list_item
else -> R.layout.vertical_horizontal_list_item
}
// Inflate the layout
val adapterLayout =LayoutInflater.from(parent.context)
.inflate(layoutType, parent, false)
// Null should not be passed into the view holder. This should be updated to reflect
// the inflated layout.
return DogCardViewHolder(adapterLayout)
}
override fun getItemCount(): Int = data.size
override fun onBindViewHolder(holder: DogCardViewHolder, position: Int) {
val resources = context?.resources
// Get the data at the current position
val item = data[position]
// Set the image resource for the current dog
holder.imageView.setImageResource(item.imageResourceId)
// Set the text for the current dog's name
holder.dogName.text = item.name
// Set the text for the current dog's age
holder.dogAge.text = resources?.getString(R.string.dog_age, item.age)
// Set the text for the current dog's hobbies by passing the hobbies to the
// R.string.dog_hobbies string constant.
holder.dogHobbies.text = resources?.getString(R.string.dog_hobbies, item.hobbies)
// Passing an argument to the string resource looks like:
// resources?.getString(R.string.dog_hobbies, dog.hobbies)
// Set the dog's sex variable
holder.dogSex = item.sex
// Declare context var
val context = holder.itemView.context
// Setting up OnClickListener
holder.showDetailsButton.setOnClickListener {
val intent = Intent(context, DetailActivity::class.java)
intent.putExtra(DOG_IMAGE, item.imageResourceId.toInt())
intent.putExtra(DOG_NAME, holder.dogName.toString())
intent.putExtra(DOG_AGE, holder.dogAge.toString())
intent.putExtra(DOG_HOBBIES, holder.dogHobbies.toString())
intent.putExtra(DOG_SEX, holder.dogSex.toString())
context.startActivity(intent)
}
}
}

Mapbox Fixed Location in Android

How do I show a location marker for a fixed location? All am getting from the docs is user location or current location. The task I want to achieve is to get coordinates of a certain location and have a marker appear at that particular location.
Below is the code I tried with but the marker appears somewhere else:
package com.show.show_map
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Bundle
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import com.mapbox.geojson.Point
import com.mapbox.maps.MapView
import com.mapbox.maps.Style
import com.mapbox.maps.plugin.annotation.annotations
import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions
import com.mapbox.maps.plugin.annotation.generated.createPointAnnotationManager
import okhttp3.logging.HttpLoggingInterceptor
class AbsaLocationActivity : AppCompatActivity() {
private var mapView: MapView? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_absa_location)
val BASIC = "mapbox://styles/stunupps/cl2f3q6b1002d14o6wpu3m6bq"
mapView = findViewById(R.id.mapView)
mapView?.getMapboxMap()?.loadStyleUri(
HttpLoggingInterceptor.Level.BASIC,
object : Style.OnStyleLoaded {
override fun onStyleLoaded(style: Style) {
addAnnotationToMap()
}
}
)
}
private fun addAnnotationToMap() {
// Create an instance of the Annotation API and get the PointAnnotationManager.
bitmapFromDrawableRes(
this#AbsaLocationActivity,
R.drawable.red_marker
)?.let {
val annotationApi = mapView?.annotations
val pointAnnotationManager = annotationApi?.createPointAnnotationManager()
// Set options for the resulting symbol layer.
val pointAnnotationOptions: PointAnnotationOptions = PointAnnotationOptions()
// Define a geographic coordinate.
.withPoint(Point.fromLngLat(-15.39, 28.31))
// Specify the bitmap you assigned to the point annotation
// The bitmap will be added to map style automatically.
.withIconImage(it)
// Add the resulting pointAnnotation to the map.
pointAnnotationManager?.create(pointAnnotationOptions)
}
}
private fun bitmapFromDrawableRes(context: Context, #DrawableRes resourceId: Int) =
convertDrawableToBitmap(AppCompatResources.getDrawable(context, resourceId))
private fun convertDrawableToBitmap(sourceDrawable: Drawable?): Bitmap? {
if (sourceDrawable == null) {
return null
}
return if (sourceDrawable is BitmapDrawable) {
sourceDrawable.bitmap
} else {
// copying drawable object to not manipulate on the same reference
val constantState = sourceDrawable.constantState ?: return null
val drawable = constantState.newDrawable().mutate()
val bitmap: Bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth, drawable.intrinsicHeight,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
bitmap
}
}
}

IllegalArgumentException: maxHeight(473) must be >= minHeight(747)

I'm trying out an example from Jetpack Compose and got this error below, I have not changed nothing since this code worked before, the only thing that I have changed was the version from dev15 to alpha-01 and then this happened
java.lang.IllegalArgumentException: maxHeight(473) must be >= minHeight(747)
at androidx.compose.ui.unit.Constraints.copy-msEJaDk(Constraints.kt:158)
at androidx.compose.ui.unit.Constraints.copy-msEJaDk$default(Constraints.kt:146)
at androidx.compose.ui.draw.PainterModifier.modifyConstraints-BRTryo0(PainterModifier.kt:224)
at androidx.compose.ui.draw.PainterModifier.measure-3Jkh9V0(PainterModifier.kt:91)
at androidx.compose.ui.node.ModifiedLayoutNode.performMeasure-BRTryo0(ModifiedLayoutNode.kt:36)
at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:120)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(DelegatingLayoutNodeWrapper.kt:106)
at androidx.compose.ui.node.LayerWrapper.performMeasure-BRTryo0(LayerWrapper.kt:70)
at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:120)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(DelegatingLayoutNodeWrapper.kt:106)
at androidx.compose.ui.node.LayerWrapper.performMeasure-BRTryo0(LayerWrapper.kt:70)
at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:120)
at androidx.compose.foundation.layout.FillModifier.measure-3Jkh9V0(LayoutSize.kt:433)
at androidx.compose.ui.node.ModifiedLayoutNode.performMeasure-BRTryo0(ModifiedLayoutNode.kt:36)
at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:120)
at androidx.compose.foundation.layout.SizeModifier.measure-3Jkh9V0(LayoutSize.kt:507)
at androidx.compose.ui.node.ModifiedLayoutNode.performMeasure-BRTryo0(ModifiedLayoutNode.kt:36)
at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:120)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:90)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:132)
at androidx.compose.ui.platform.AndroidComposeView.observeMeasureModelReads(AndroidComposeView.kt:425)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:89)
at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:62)
at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1095)
at androidx.compose.foundation.layout.RowColumnImplKt$rowColumnMeasureBlocks$1.invoke(RowColumnImpl.kt:90)
at androidx.compose.foundation.layout.RowColumnImplKt$rowColumnMeasureBlocks$1.invoke(RowColumnImpl.kt)
at androidx.compose.ui.LayoutKt$measureBlocksOf$1.measure-2MWCACw(Layout.kt:146)
at androidx.compose.ui.node.InnerPlaceable.performMeasure-BRTryo0(InnerPlaceable.kt:48)
at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:120)
at androidx.compose.foundation.layout.PaddingModifier.measure-3Jkh9V0(LayoutPadding.kt:169)
at androidx.compose.ui.node.ModifiedLayoutNode.performMeasure-BRTryo0(ModifiedLayoutNode.kt:36)
at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:120)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:90)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:132)
at androidx.compose.ui.platform.AndroidComposeView.observeMeasureModelReads(AndroidComposeView.kt:425)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:89)
at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:62)
at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1095)
at androidx.compose.foundation.lazy.LazyForState.measure-mw7JCkE(LazyForState.kt:322)
at androidx.compose.foundation.lazy.
My code is the followin
import android.os.Bundle
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.Image
import androidx.compose.foundation.Text
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumnFor
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.unit.dp
import androidx.ui.tooling.preview.Preview
import com.example.jetexample.ui.typography
val recipeList = listOf<Recipe>(Recipe(R.drawable.header,"Test", listOf("Azucar","Tomate","lasagna")),
Recipe(R.drawable.header,"Test", listOf("Azucar","Tomate","lasagna")),
Recipe(R.drawable.header,"Test", listOf("Azucar","Tomate","lasagna")))
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
RecipeList(recipeList)
}
}
}
#Composable
fun RecipeCard(recipe: Recipe) {
val image = imageResource(R.drawable.header)
Column(modifier = Modifier.padding(16.dp)) {
val imageModifier = Modifier
.preferredHeightIn(maxHeight = 180.dp)
.fillMaxWidth()
.clip(shape = RoundedCornerShape(8.dp))
Image(image,modifier= imageModifier, contentScale = ContentScale.Crop)
Spacer(Modifier.preferredHeight(16.dp))
Text(recipe.title, style = typography.h6)
for(ingredient in recipe.ingredients){
Text(ingredient,style = typography.body2)
}
}
}
#Composable
fun RecipeList(recipeList:List<Recipe>){
LazyColumnFor(recipeList) { item ->
RecipeCard(recipe = item)
}
}
#Preview(showBackground = true)
#Composable
fun RecipePreview(){
RecipeList(recipeList)
}
data class Recipe(
#DrawableRes val imageResource: Int,
val title: String,
val ingredients: List<String>
)
I think the problem might be in the dp units imported, I really dont know why this happends
Fixed by replacing
.preferredHeightIn(maxHeight = 180.dp)
with
.preferredHeightIn(180.dp)

App is shutting down unexpectedly - Kotlin

package com.example.firstapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.EditText
import kotlinx.android.synthetic.main.activity_main.*
import kotlin.random.Random
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val deEditText = findViewById<EditText>(R.id.de) as EditText
val ateEditText = findViewById<EditText>(R.id.ate) as EditText
Randomize.setOnClickListener{
val de = Integer.parseInt(deEditText.text.toString())
val ate = Integer.parseInt(ateEditText.text.toString())
RandomDisplay.text = (Random.nextInt(de - ate) + ate).toString()
}
}
}
I'm trying to create an app that gets two values and picks a random integer between them. I don't know what I'm doing wrong, and I really hope someone can help me. Thanks in advance.
val deEditText = findViewById<EditText>(R.id.de) as EditText
val ateEditText = findViewById<EditText>(R.id.ate) as EditText
Random.nextInt(de - ate)
if value from deEditText minus value from ateEditText is zero or negative, Radom.nextInt would throw IllegalArgumentException
// minimize the end bound to 1 by adding max()
RandomDisplay.text = (Random.nextInt(max(1, de - ate)) + ate).toString()

Categories

Resources