I have a text view to which I need to create a listener for onLongClick. Right now for the respective viewmodel it has a function sendLogs() which deals with the logic for onClick. If I change onClick to onLongClick function never get call. Is there any way to make it work for onLongClick?
onClick is directly linked to my model class function but not the onLongClick. So I think model class binding is correct but I may need some extra work here.
<data>
<import type="android.view.View" />
<variable
type="com.aaa.bbb.viewmodel.SystemSettingsViewModel"
name="systemSettings"
</variable>
</data>
<TextView
android:gravity="end"
android:id="@+id/tv_logging"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_width="wrap_content"
android:onClick="@{() -> systemSettings.sendLogs()}"
android:text="@string/enable_logs"
android:textAlignment="viewEnd" />
In the xml section, you must refer to the Boolean return function, such as the following code, so as not to get into trouble.in build project android studio
in xml
android:onLongClick="@{(view) -> presenter.onLongClick(view)}"
in java
public boolean onLongClick(View v) {
return false;
}
I managed to work it correctly. I doubt this is properly documented.
In xml
android:onLongClick="@{(view) -> presenter.onLongClickOnHeading(view)}"
In presenter viewmodel class
public boolean onLongClickOnHeading(View v) {
//logic goes here
return false;
}
Note: this method signature should be exactly in this format. Otherwise biding errors will be thrown at runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With