logo
down
shadow

How do I inherit a function from another class into an activity in kotlin?


How do I inherit a function from another class into an activity in kotlin?

By : Jayant Kumar jaiswal
Date : October 19 2020, 08:10 AM
Hope this helps Let me add a bit on top of iFanie's answer.
What he says is true. In Java as in Kotlin, multiple inheritance is not allowed. A class can only extend 1 class but can implement many interfaces.
code :
interface MyInterface {
    val prop: Int // abstract

    val propertyWithImplementation: String
        get() = "foo"

    fun foo() {
        print(prop)
    }
}

class Child : MyInterface {
    override val prop: Int = 29
}


Share : facebook icon twitter icon
Inherit from abstract class with multiply vars in Kotlin

Inherit from abstract class with multiply vars in Kotlin


By : TriCyclist
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Check the documentation about inheritance
Since you have a primary constructor you will have to pass the parameters to super:
code :
abstract class Animal(var name: String, var age: Int, var mother: Animal, 
                      var father: Animal, var friends: ArrayList<Animal>)

class Cat(name: String, age: Int, mother: Animal, 
          father: Animal, friends: ArrayList<Animal>) 
          : Animal(name, age, mother, father, friends)
Kotlin: How to inherit property in data class

Kotlin: How to inherit property in data class


By : Sissel Zacho
Date : March 29 2020, 07:55 AM
wish helps you I have abstract Token class declared like this: , There are at least two workarounds:
code :
abstract class Token(open var index: Int = 0)

data class CloseLoop(
    override var index: Int, 
    var openLoopIndex: Int = 0
) : Token(index)
data class CloseLoop(val theIndex: Int, var openLoopIndex: Int = 0) : Token(theIndex)
Kotlin: inherit from a nested Java class

Kotlin: inherit from a nested Java class


By : user2070612
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The equivalent of Java's non-static nested class in Kotlin is inner class.
To make your code work, you need to use inner keyword:
code :
class DerivedOuter() : BaseOuter() {
    inner class DerivedInner : BaseOuter.BaseInner() {
    }
}
How to call a function from within the same class activity in Kotlin? - How to loop CountDowntimer from its own class

How to call a function from within the same class activity in Kotlin? - How to loop CountDowntimer from its own class


By : user3193292
Date : March 29 2020, 07:55 AM
Hope that helps Is txtBig kotlin synthetic view or a local variable or global variable?
if txtBig is kotlin synthetic view, you should be able to call it.
code :
class MainActivity : AppCompatActivity() {
    private lateinit var txtBig: TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        txtBig = findViewById<TextView>(R.id.txt_big) // Your id in xml

        tapAction.setOnClickListener{
            boTimeRunning = !boTimeRunning
            if(boTimeRunning ){
                goCountdown()
            }
        }
    }

    fun goCountdown(){
        object : CountDownTimer1(timeSettings_set * 1000, 1000){
            override fun onTick(p0: Long) {
                txtBig.text = "sometext"
            }
            override fun onFinish() {
                goCountdown()
            }
        }.start()
    }
}
Android Kotlin - How do I assign a name function in main activity class to setOnClickListener in another class?

Android Kotlin - How do I assign a name function in main activity class to setOnClickListener in another class?


By : user3557508
Date : March 29 2020, 07:55 AM
it fixes the issue Please check the sample code and comments below, , Just pass the Listener instance to the adapter:- like :-
code :
val adapter = AnotherClass(this@MainActivity)
class AnotherClass(private val listener: MainActivity): RecyclerView.Adapter<MyAdapter.ViewHolder>() {
     ....
     ....
     holder.itemView.setOnClickListener {
         listener.OnViewItemClicked()
     }
     ....
 }
val clickLambda: (View) -> Unit = {
    listener.OnViewItemClicked()
}
Related Posts Related Posts :
  • How to employ keyed-hash message authentication code (HMAC) with Android Keystore
  • Prevent inviting existing users or previously invited
  • How to overwrite windowSoftInputMode using edit-config tag in cordova
  • Difference between Loader and AsyncTask
  • In Firebase Android, retrieve the value of a child node and save it in a boolean variable
  • when i scroll the custom list in my android app then the favorite icon which is part of the custom adapter changes on it
  • adding room dependency gives manifest merge error
  • Visibility of RelativeLayout change on scrolling Gridview
  • Strange LiveData behavior vs ObservableField
  • Which layout is used for clash of clans home screen? We can scroll it horizontal as well as vertical. Please illuminate
  • RxJava: Know when observable is finished and return Boolean Observable to the caller
  • how to use savedInstanceState to save camera information when the orientation change occure
  • Style React-Native via Styles.xml
  • Keyboard won't show after calling InputMethodManager.showSoftInput
  • Compiling ffmpeg for Android on OSX
  • Button does not get clicked on the first attempt
  • AR Core performance, learning curve and comparison with other frameworks
  • Codename one : Attaching images to email message fails
  • Error: Unsupported type 'viewItem' in Android build
  • setLayoutParams on ConstraintLayout does not change size
  • How to profile the fetch time of the android gradle libraries
  • Kotlin setOnclickListener
  • Naming convention for methods returning RxJava's Completable
  • Conv3D not working
  • FFmpeg audio video merge command
  • Do you have to use gradle-experimental for JNI?
  • How to get key hashes for facebook for facebook app?
  • ZXing not calling onActivityResult, When scanning QR Code
  • Integration of Android Native module with existing Xamarin Native Project
  • Restore RecyclerView state after rotating
  • ViewModelProviders java.lang.RuntimeException trying to instantiate class which inherit AndroidViewModel
  • SKD19 vs SDK24 - Usage of API documented as @since 1.8+
  • filter option in list view fragment activity
  • Picture from camera not showing up in second activity
  • How to change imageview according to screen size
  • How to copy Android Studio project to remote Git (NOT GitHub) server
  • How to get React-Native to announce specific accessibility message via AccessibiliyManager?
  • Change colors of com.tech.freak.wizardpager.ui.StepPagerStrip
  • Android fullscreen activity shows ActionBar
  • Turn on the screen when timer calls onFinish()
  • Would like a bit of clarification with SQLite database's onUpgrade method
  • Use ObjectBox with Libgdx
  • How to make combine Gregorian and Hijri calendar in Android?
  • Try to read text file from sdcard in other language
  • "App not installed" message when installed apk
  • How to execute a designated test suite class in Firebase Test Lab
  • play music with background service
  • background not visible on LG G3
  • should every View have an id?
  • Realm object server sync on low connection.
  • Correct way to add more views to adapter
  • Getting error in android support library
  • Instant app zip uploading error
  • "No emulator installed" error in Android Studio even though Intel HAXM is up and running
  • AsyncTask without leaks
  • SQLiteException : No such table found whereas a table was created
  • Using @Component.Builder with constructor params
  • No injector was found for fragment dagger 2.11
  • Android Volley Https SSL self signed and Google Maps API
  • Why does the onClickListener not work anymore in this example?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org