Kotlin Cast EditText, TextView to View
Tag : java , By : user185949
Date : March 29 2020, 07:55 AM
Hope this helps i have one static method in kotlin to hide soft keyboard, it works in java if i pass EditText, TextView as second parameter of method. , Try to change code View to View? companion object {
fun hideSoftKeyboard(activity: Activity, view: View?) {
view?.let {
val imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(it.applicationWindowToken, 0)
}
}
}
|
Kotlin Custom View referencing textview returns null
Date : March 29 2020, 07:55 AM
With these it helps I have a Custom view: , You have to add parent layout as parameter to 'inflate' method. class CustomerView(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
private var txtName: TextView
private var txtAge: TextView
init {
View.inflate(context, R.layout.view_customer, this)
txtName = findViewById(R.id.txtTestName)
txtAge = findViewById(R.id.txtTestAge)
txtName.text = "Derek"
txtAge.text = "23"
}
}
|
Edittext and textview inside recyclerview Android kotlin scrolling issue
Date : March 29 2020, 07:55 AM
To fix the issue you can do You need to have an array of quantities in the KartListAdapter to save the quantities. The values are disappearing an showing wrongly is because the views are getting recycled in the RecyclerView. So you need to save the sates of each row in a separate ArrayList and then show the quantities from there. Hence I would like to propose having a separate ArrayList in your KartListAdapter like var quantityList: List .holder.itemsqty.text = quantityList[position];
holder.btnIncrease.setOnClickListener() {
quantityList[position] = quantityList[position] + 1;
notifyDataSetChanged();
}
holder.btnDecrease.setOnClickListener() {
if(quantityList[position] > 0) {
quantityList[position] = quantityList[position] - 1;
notifyDataSetChanged();
}
}
|
Retrieve a TextView Value inside a Adapter Class in Kotlin
Date : March 29 2020, 07:55 AM
I wish this help you I assume that the textview's id is movieCount and this is what you need inside the adapter. In your activity create this method: fun getCount(): String {
return movieCount.text.toString()
}
inner class MoviesAdapter(context: Context) : RecyclerView.Adapter<MoviesAdapter.MovieViewHolder>()
val activity: MainActivity = context as MainActivity
activity.getCount()
recyclerview.adapter = MoviesAdapter(this)
|
Kotlin - How to create a class member function similar to TextView.setText(String) that can be invoked as TextView.text
Date : March 29 2020, 07:55 AM
This might help you What i am trying to create is a Custom AlertDialogBox for which i would like to invoke the "setTitle()" method as alertObject.title = "SomeTitle". My current AlertDialog code is as below , You need to define a property: var text: String
get() = txt_title.text
set(value) { txt_title.text = value }
|