kotlin-android-extensions

How to add an item to an ArrayList in Kotlin?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 23:15:55
How to add an item to an ArrayList in Kotlin? guenhter If you have a MUTABLE collection: val list = mutableListOf(1, 2, 3) list += 4 If you have an IMMUTABLE collection: var list = listOf(1, 2, 3) list += 4 note that I use val for the mutable list to emphasize that the object is always the same, but its content changes. In case of the immutable list, you have to make it var . A new object is created by the += operator with the additional value. Tarun For people just migrating from java , In Kotlin List is by default immutable and mutable version of Lists is called MutableList . Hence if you

Kotlin Android View Binding: findViewById vs Butterknife vs Kotlin Android Extension

南笙酒味 提交于 2019-12-02 22:23:10
I'm trying to figure out the best way to do Android View Binding in Kotlin. It seems like there are a few of options out there: findViewById val button: Button by lazy { findViewById<Button>(R.id.button) } Butterknife https://github.com/JakeWharton/butterknife @BindView(R.id.button) lateinit var button: Button Kotlin Android Extensions https://kotlinlang.org/docs/tutorials/android-plugin.html import kotlinx.android.synthetic.main.activity_main.* I'm pretty familiar with findViewById and Butterknife in java land, but what are the pros and cons of each view binding approach in Kotlin? Does

Unresolved reference for synthetic view when layout is in library module

限于喜欢 提交于 2019-12-02 16:45:20
using Kotlin 1.20.20 (not that it matters, older versions behaves the same) When layout is in separate library module Android Studio has no problem finding and referencing the view import kotlinx.android.synthetic.main.view_user_input.* But when I try to compile app it fails with Unresolved reference: view_user_input on :app:compileDebugKotlin . Everything works fine when view is referenced IN the library module. Am I missing something here? Adding project structure. All modules are using kotlin and kotlin-extensions. build.gradle app/ build.gradle //main application library-module-a/ build

The difference between !! and ? in Kotlin

时光怂恿深爱的人放手 提交于 2019-12-02 16:08:19
I am new to Kotlin . I want to know the difference between this two !! and ? in below code. I am having below two snippet first having use of !! for mCurrentDataset and another having ? for same variable. if(!mCurrentDataset!!.load(mDataSetString.get(mCurrentDataSelectionIndex), STORAGE_TYPE.STORAGE_APPRESOURCE)) { Log.d("MyActivity","Failed to load data.") return false } if(!mCurrentDataset?.load(mDataSetString.get(mCurrentDataSelectionIndex), STORAGE_TYPE.STORAGE_APPRESOURCE)!!) { Log.d("MyActivity","Failed to load data.") return false } Thanks in advance. As it said in Kotlin reference , !!

Parsing xml kotlin android

99封情书 提交于 2019-12-02 11:46:09
问题 I have xml like this: <horo> <aries> <today> Сегодня вас могут здорово огорчить. Если от расстройства все начнет валится из рук, просто спокойно сядьте и тихонько подождите хорошей новости. </today> </aries> <taurus> <today> Сегодня у вас могут возникнуть проблемы на личном фронте. Спасти вас от перспективы оказаться не у дел может сухой, рациональный и в высшей степени объективный подход к проблеме. </today> </taurus> </horo> And now i learning kotlin whith retrofit. I include libraries for

Unable to get data from sqlite database

此生再无相见时 提交于 2019-12-02 08:04:10
The problem is that when I run my code the app is stopping with an error (java.lang.RuntimeException: Unable to start activity ComponentInfo{com.twixt.pranav.pos/com.twixt.pranav.pos.View.Activity.Cart}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getDatabasePath(java.lang.String)' on a null object reference) in the code you could see that I have inserted one data manually I have seen similar questions but no solutions for it This is my class class FragmentCart : Fragment() { private val database: SQLiteHelper = SQLiteHelper(activity)

Parsing xml kotlin android

安稳与你 提交于 2019-12-02 07:23:22
I have xml like this: <horo> <aries> <today> Сегодня вас могут здорово огорчить. Если от расстройства все начнет валится из рук, просто спокойно сядьте и тихонько подождите хорошей новости. </today> </aries> <taurus> <today> Сегодня у вас могут возникнуть проблемы на личном фронте. Спасти вас от перспективы оказаться не у дел может сухой, рациональный и в высшей степени объективный подход к проблеме. </today> </taurus> </horo> And now i learning kotlin whith retrofit. I include libraries for parse xml, and not i cant understand how create object for parsing this xml. I have object: @Root(name

Kotlin RC NoClassDefFoundError

我的梦境 提交于 2019-12-02 07:05:56
After updating kotlin to RC-1036 i'm facing a weird issue: my code is not even compiled and packed. When build passes and the app is launched i'm getting ClassNotFoundException: Didn't find class "example.myapplication.MainActivity" . I have tried to decompile apk with apktool and didn't find my classes inside the archive. There are no classes in build/intermediates dir either. This is my project: app/build.gradle : apply plugin: 'com.android.application' apply plugin: 'kotlin-android-extensions' buildscript { ext.kotlin_version = '1.0.0-rc-1036' repositories { mavenCentral() } dependencies {

Kotlin custom dialog Parameter specified as non-null

可紊 提交于 2019-12-01 15:13:54
I got this error : Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState When i am trying to inflate a custom dialog in Kotlin , i got the error i wrote above on the super.onCreate line in the dialog. the dialog code is : class Custom_Dialog_Exit_App(var activity: Activity)// TODO Auto-generated constructor stub : Dialog(activity, R.style.full_screen_dialog) { override fun onCreate(savedInstanceState: Bundle) { super.onCreate(savedInstanceState) requestWindowFeature

Error:(1, 0) Plugin with id 'kotlin-android-extensions' not found

和自甴很熟 提交于 2019-12-01 02:09:31
apply plugin: 'kotlin-android-extensions'. When i add this extensions in android studio preview, give me this error "Error:(1, 0) Plugin with id 'kotlin-android-extensions' not found.". My build gradle apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.1" defaultConfig { applicationId "com.example.mohamed_elbaz.myapplication" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(