Android-kotlin-binding doesn't update the properties [duplicate] - android

This question already has an answer here:
Kotlin android. binding not update data
(1 answer)
Closed 5 years ago.
My problem is the binding is work, but not correctly! When I type new text in textfield and then try to get data from this textfield with help binding, I see old data. I tried to find the mistake, but I couldn't.
My activity_fblogin.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey_main"
android:descendantFocusability="beforeDescendants"
android:fitsSystemWindows="true"
android:focusableInTouchMode="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context="com.example.darkt.makeyouself.activities.FBLogin"
tools:ignore="MissingConstraints">
<EditText
android:id="#+id/userName"
android:layout_width="220dp"
android:layout_height="43dp"
android:ems="10"
android:inputType="textPersonName"
android:text="test01"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Login"/>
<EditText
android:id="#+id/userPass"
android:layout_width="220dp"
android:layout_height="45dp"
android:layout_marginTop="25dp"
android:ems="10"
android:inputType="textPassword"
android:text="123456"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/userName"
tools:layout_editor_absoluteX="74dp"
tools:layout_editor_absoluteY="245dp"
tools:text="Password"/>
<Button
android:id="#+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Login"
android:textColor="#color/green_main"
app:layout_constraintEnd_toEndOf="#+id/userPass"
app:layout_constraintTop_toBottomOf="#+id/userPass" />
</android.support.constraint.ConstraintLayout>
</layout>
It is my kotlin class for fblogin_activity. I was trying to fixed this problem, but ... Give me idea please!
package com.example.darkt.makeyouself.activities
class FBLogin : AppCompatActivity() {
private var binding: ActivityFbloginBinding? = null
private var auth: FirebaseAuth? = null
private var dbHelper: FirebaseHelper? =null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_fblogin)
auth = FirebaseAuth.getInstance()
dbHelper = FirebaseHelper()
setContentView(R.layout.activity_fblogin)
binding?.executePendingBindings()
signIn.setOnClickListener{_ -> showSignInActivity()}
}
private fun loginToSystem() {
val email = binding?.userName?.text.toString().trim()
val password = binding?.userPass?.text.toString()
binding?.executePendingBindings()
Toast.makeText(this, email, Toast.LENGTH_SHORT).show()
Toast.makeText(this, password, Toast.LENGTH_SHORT).show()
}
}
Example mistake

There is nothing in your layout xml that actually uses databinding.
first in your tag, you will need to define an object to reference for data binding. for example:
<data>
<variable name="user" type="com.myapp.User"/>
</data>
further down in the username/password field you would need to reference this user for the text field
<EditText
android:id="#+id/userName"
android:layout_width="220dp"
android:layout_height="43dp"
android:ems="10"
android:inputType="textPersonName"
android:text="#={user.username}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<EditText
android:id="#+id/userPass"
android:layout_width="220dp"
android:layout_height="45dp"
android:layout_marginTop="25dp"
android:ems="10"
android:inputType="textPassword"
android:text="#={user.password}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/userName"
tools:layout_editor_absoluteX="74dp"
tools:layout_editor_absoluteY="245dp"/>
Note the #={user.username} in the text field. For every property of the class user, you will need to specify a setter/getter. the #= means, update the underlying object when this value changes.
before your "executePendingBindings" you will need to do something like this:
val user = User()
binding.setVariable(BR.user, user)
binding.executePendingBindings()
then you should be good to go.

Related

editableText is not working in android studio

I want to take Input from user(their name) with editableText just like the below video(watch at 8:24). But, I am not able to take input because android studio is not recognizing "editableText". Am i missing something?
Android Development Tutorial Video at 8:24
Error ->>
Unresolved reference: nameInput [In the below MainActivity.kt]
MainActivity.kt
package com.example.firstapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
fun createBirthdayCard(view: View){
val name = nameInput.**editableText**.toString() <-- [error is in this line]
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="140dp"
android:text="Enter Name"
android:textColor="#000000"
android:textSize="50sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:textAlignment="center" />
<EditText
android:id="#+id/nameInput"
android:layout_width="280dp"
android:layout_height="54dp"
android:layout_marginTop="64dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
android:textSize="25sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3"
tools:textAlignment="center" />
<Button
android:id="#+id/createBirthdayCard"
android:layout_width="307dp"
android:layout_height="81dp"
android:layout_marginTop="144dp"
android:maxLines="1"
android:text="Create Birthday Card"
android:textSize="19sp"
android:onClick="createBirthdayCard"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/nameInput"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
:) :) Thanks for spending your valuable time to help me :) :)
Android kotlin extensions removed at Android studio 4.1V.
I recommend use the ViewBinding or DataBinding.
This is a good reference.
https://android-developers.googleblog.com/2020/11/the-future-of-kotlin-android-extensions.html
ViewBinding : https://developer.android.com/topic/libraries/view-binding?hl=ko
DataBinding : https://developer.android.com/topic/libraries/data-binding
As Android kotlin extensions is deprecated and removed you may use
View binding, Data binding as suggested by Seungho Kang
OR you can declare variable as shown below.
fun createBirthdayCard(view: View){
val editText=findViewById<EditText>(R.id.nameInput)
val name = editText.editableText.toString()
}

On the Java side, I get Famous error: on a null object object In the event that definition conditions "findVIewById" are correct

On the Java side, I get Famous error: on a null object object In the event that definition conditions "findVIewById" are correct .
It is interesting that textView With id :#+id/txt_detail_pPrice is identified but #+id/txt_detail_Price NO and throw :on a null object
why findVIewById does not work just for #+id/txt_detail_Price and "price" in java side become
null??
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_details)
val imgProduct=findViewById< MyImageView >(R.id.img_details_showpicProduct)
val txt_title=findViewById<TextView >(R.id.txt_detail_showTitle)
val waranty=findViewById< TextView >(R.id.txt_details_waranty)
val pPrice=findViewById< TextView >(R.id.txt_detail_pPrice)
val price=findViewById<TextView>(R.id.txt_detail_Price)
val color=findViewById< TextView >(R.id.txt_details_color)
val detailIntroduction=findViewById<TextView>(R.id.txt_details_introduction)
val ratingBar=findViewById<RatingBar>(R.id.details_ratingBar_showratingProduct)
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Details.DetailsActivity">
<com.google.android.material.appbar.AppBarLayout...>
<androidx.core.widget.NestedScrollView...>
<RelativeLayout
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:background="#color/purple_500"
android:layout_height="75dp">
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:backgroundTint="#color/greenIcon"
android:text="افزودن به سبد خرید"
android:textColor="#color/white" />
<TextView
android:id="#+id/txt_detail_pPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="10000000میلیون"
android:textColor="#color/teal_700" />
<TextView
android:id="#+id/txt_detail_Price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="20000000میلیون"
android:textColor="#color/black" />
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
If you are quite certain the corresponding view that it can't find is in the layout you passed to setContentView, I think the most likely cause for this issue is that you have multiple versions of this same layout for different screen configurations, and forgot to include a view with this ID in all of them. When the screen is in a configuration where the view is not included, it cannot be found.

Validation using binding adapter

i need some clearance in my concept of understanding the binding adapter implementation.
I am designing a login form with two input fields and a button. I'm trying to use binding adapter to validate those fields using text watcher (which is working fine).
But i'm lost that how can i validate those fields on click of the button.
i'm trying to achieve a clean architecture and remove all kind of dependency between view and ViewModel.
login_activity.xml
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="authModel"
type="com.jpm.ui.auth.AuthViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorSurface"
tools:context=".ui.auth.LoginActivty">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/logo"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="60dp"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/jpm_logo" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/layoutLoginId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="40dp"
android:hint="#string/login_id_hint"
app:layout_constraintTop_toBottomOf="#id/logo"
app:startIconDrawable="#drawable/ic_user"
nullCheck="#{#string/nullError}">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/inputLoginId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#={authModel.inputLoginId}" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/layoutPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="40dp"
android:hint="#string/password"
app:layout_constraintTop_toBottomOf="#id/layoutLoginId"
app:passwordToggleEnabled="true"
app:startIconDrawable="#drawable/ic_locked">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/inputPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#={authModel.inputPassword}" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/btnSignIn"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="30dp"
android:background="#drawable/bg_primary_rounded"
android:onClick="#{authModel::authClickListener}"
android:paddingStart="40dp"
android:paddingEnd="40dp"
android:text="#string/sign_in"
android:textColor="#color/textSecondary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/layoutPassword" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/labelCreateAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="#string/don_t_have_an_account"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#id/txtCreateAccount"
app:layout_constraintTop_toBottomOf="#id/btnSignIn" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/txtCreateAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="20dp"
android:onClick="#{authModel::authClickListener}"
android:text="#string/create_account"
android:textColor="#color/colorPrimary"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintLeft_toRightOf="#id/labelCreateAccount"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/btnSignIn" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/txtSkip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:onClick="#{authModel::authClickListener}"
android:text="#string/skip"
android:textColor="#color/textGrey"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/txtCreateAccount" />
</androidx.constraintlayout.widget.ConstraintLayout>
ValidationUtils.class
import android.util.Log
import androidx.core.widget.doAfterTextChanged
import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import androidx.databinding.BindingAdapter
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.google.common.base.Predicates
import com.jpm.R
object ValidationUtils : BaseObservable() {
const val TAG = "VALIDATION"
#BindingAdapter("nullCheck")
#JvmStatic
fun setError(inputLayout: TextInputLayout, errorMsg: String) {
inputLayout.editText?.doAfterTextChanged {
if (it.isNullOrEmpty()) {
inputLayout.isErrorEnabled = true
inputLayout.error = errorMsg
} else {
inputLayout.isErrorEnabled = false
inputLayout.error = null
}
}
}
}
Please help with some suggestion or what can i implement to achieve the validation on button click.
**PS - On Validation on button click setError should be applied on EditText as well **
This is what I'd use in your case:
When your ViewModel's authClickListener() is called, you check/validate every input that is bound with two-way databinding, in your case inputLoginId and the password.
Additionally you set up two error observables, with the type String?, tie does to the error of the respective TextInputLayout and just modify the error messages according to your validation logic

Bindable must be on a member in an Observable class

I'm new in data binding , this is my code but I get this error on building
class DatabindingViewModel :ViewModel() {
val currentFruitName:LiveData<String>
get() = FakeRepository.currentName
fun changeNameOnClick()=FakeRepository.changeRandomFoodName()
//two way LiveData
#Bindable
val editTextContext= MutableLiveData<String>()
private val _displayEditTexfContent=MutableLiveData<String>()
val displayEditTexfContent:LiveData<String>
get()=_displayEditTexfContent
fun onDisplayEtText(){
_displayEditTexfContent.value=editTextContext.value
}
this is my xml layout code :
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="binding"
type="ir.persiandesigners.myapplication.databinding.viewmodel.DatabindingViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:text="#{binding.currentFruitName}"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:onClick="#{()->binding.changeNameOnClick()}"
android:text="Get Random Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="60dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="#={binding.editTextContext}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:onClick="#{()->binding.onDisplayEtText()}"
android:text="Change Display Text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
this is the code I've in the activity:
val viweModel= ViewModelProviders.of(this)
.get(DatabindingViewModel::class.java)
DataBindingUtil.setContentView<ActvitiyDatadindingBinding>(
this,R.layout.actvitiy_datadinding)
.apply {
this.setLifecycleOwner( this#DataBindingAct)
this.binding=viweModel
}
viweModel.editTextContext.observe(this, Observer{
Toast.makeText(this#DataBindingAct,it ,Toast.LENGTH_LONG).show()
})
when I want to build the project and run it , I get this error :
e: error: Bindable must be on a member in an Observable class. DatabindingViewModel is not Observable
could you help me ?
I've tried to clean the project , rebuild and so on but there is an error in my code that I couldn't find
could you help me ?
Just remove #Bindable annotation from Viewmodel and your code will run successfully and error will be resolved.
The #Bindable annotation should only be be applied when you are accessing getter method while extending BaseObservable class which itself implements Observable interface for observing data.
Here LiveData itself is an observable data holder class
So, you don't need to implement #Bindable and BaseObservable class for observing data.
docs: https://developer.android.com/reference/android/databinding/Bindable
I hope things are clear now..
You have to implement Observable Interface and add its methods
here is mine,
class MainViewModel: ViewModel(), Observable {
private val callbacks: PropertyChangeRegistry by lazy { PropertyChangeRegistry()}
override fun removeOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback?) {
callbacks.add(callback)
}
override fun addOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback?) {
callbacks.remove(callback)
}
}// class ends here
Do the following step-by-step:
Clean Project
Rebuild Project
Invalidate Caches / Restart
Trust me, it should work. I know the solution is simple but I also wasted my 3 hours 'cuz of this. Follow these 3 steps and you should be good to go.

How to move all elements in Constraint Layout Up on focus in Edit text Field?

I am trying to make a layout with an Edit Text field for email requests. The design makes it so that the keyboard is always opened over the editText View which makes it impossible to know what you are entering. I have tried many suggestions on stack overflow but most of them are for API <24 (though I don't think this has much effect on this).
In the Activity file I have tried the following:
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
In Android Manifest I have also tried the following, both in conjunction and separately:
android:windowSoftInputMode="adjustPan"
android:windowSoftInputMode="stateHidden|adjustPan"
android:windowSoftInputMode="adjustResize"
I also wrapped my layout in a ScrollView as described by Heena
here : https://stackoverflow.com/a/39867438/5635144
Below is my XML and the accompanying activity
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EmailResetActivity">
<RelativeLayout
android:id="#+id/bg"
android:layout_width="match_parent"
android:layout_height="419dp"
android:background="#drawable/signin_up_anim"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
...
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
<EditText
android:id="#+id/e_request"
android:layout_width="305dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="8dp"
android:ems="10"
android:hint="#string/email_address"
android:inputType="textEmailAddress"
android:paddingStart="10dp"
android:paddingBottom="15dp"
android:textColorHint="#color/hintgrey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.522"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/bg" />
<LinearLayout
android:layout_width="wrap_content"
android:id="#+id/buttonsContainer"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/e_request">
<Button
android:id="#+id/sendRequestBtn"
android:layout_width="150dp"
android:layout_height="45dp"
android:background="#drawable/large_btn"
android:text="#string/submit"
android:textColor="#color/white" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
class EmailResetActivity : AppCompatActivity() {
lateinit private var auth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_email_reset)
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
auth = FirebaseAuth.getInstance()
val animDrawable = resetPassInfoBg.background as AnimationDrawable
animDrawable.setEnterFadeDuration(2500)
animDrawable.setExitFadeDuration(1500)
animDrawable.start()
sendRequestBtn.setOnClickListener(View.OnClickListener {
val email = e_request.getText().toString().trim()
if (TextUtils.isEmpty(email)) {
Toast.makeText(application, "Enter your email ", Toast.LENGTH_SHORT).show()
return#OnClickListener
}
})
}
}
I would like for the layout to be moved up so the editText Field is visible but currently nothing is making it work.
Remove this line:
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
With FLAG_LAYOUT_NO_LIMITS the application is not able to calculate how to scroll your view, because your layout has no limits.

Categories

Resources