https://kotlinlang.org logo
#android
Title
# android
a

Ananiya

04/10/2020, 5:34 PM
how to generate new card view while i am touching button in kt
s

Steve

04/10/2020, 5:46 PM
you create the card view in the touch listener?
a

Ananiya

04/10/2020, 5:47 PM
then
s

Steve

04/10/2020, 5:49 PM
you add it to the view
there isn't anything special about doing it
a

Ananiya

04/10/2020, 5:52 PM
but my question is i have no card view then when i click a button it generate new card view
s

Steve

04/10/2020, 5:53 PM
Right. Do what I said
if you run into issues doing that, then you probably want to share your code and point out specifically what part you're having trouble with
a

Ananiya

04/10/2020, 5:54 PM
how to add the cardview in touch listner
wait letme send you my code
s

Steve

04/10/2020, 5:55 PM
you just do it
a

Ananiya

04/10/2020, 5:55 PM
btn1.setOnClickListner{}
s

Steve

04/10/2020, 5:56 PM
that's not code
you need to write an actual click listener before you can worry about the other stuff
You need to understand how to use buttons first: https://developer.android.com/guide/topics/ui/controls/button
a

Ananiya

04/10/2020, 6:02 PM
Copy code
val btn1: Button = findViewById(R.id.btn1)
        btn1.setOnClickListener { 
            cardview
        }
in the place of cardview what i have to add to generate new cardview while i am clicking the button
s

Steve

04/10/2020, 6:07 PM
the same thing you would normally add to generate a cardview
a

Ananiya

04/10/2020, 6:11 PM
this question is asked and solved in java would tell me in kotlin
s

Steve

04/10/2020, 6:12 PM
the technique is the same
a

Ananiya

04/10/2020, 6:13 PM
then how do i converted to kotlin
s

Steve

04/10/2020, 6:13 PM
you should learn Kotlin before you try to do that
you can also open a scratch file in Android Studio, paste the Java code in, and it will convert to Kotlin for you
a

Ananiya

04/10/2020, 6:14 PM
ok wait i will try
but there is many answer i don`t know which works
s

Steve

04/10/2020, 6:18 PM
try them
start with the first one
a

Ananiya

04/10/2020, 6:36 PM
View.add(view)
Thank you very much it works