日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android 自定义属性 双向绑定,如何解决:“在使用自定义视图实现双向数据绑定时,找不到属性’android:text’”的getter?...

發(fā)布時(shí)間:2025/3/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 自定义属性 双向绑定,如何解决:“在使用自定义视图实现双向数据绑定时,找不到属性’android:text’”的getter?... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我經(jīng)歷了許多類似的問題,但沒有一個(gè)答案似乎解決了我的問題.我實(shí)現(xiàn)了一個(gè)自定義EditText,我希望與雙向數(shù)據(jù)綁定兼容.問題是,每次我嘗試編譯時(shí)都會(huì)收到錯(cuò)誤:

Error:java.lang.IllegalStateException: Failed to analyze: android.databinding.tool.util.LoggedErrorException: Found data binding errors.

****/ data binding error ****msg:Cannot find the getter for attribute 'android:text' with value type java.lang.String on com.app.toolkit.presentation.view.CustomEditText. file:/Users/humble-student/Home/workspace/android/application/app/src/main/res/layout/login_view.xml loc:68:8 - 81:69 ****\ data binding error ****

at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:57)

at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:137)

at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:158)

at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:61)

at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:107)

at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)

at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)

at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:386)

at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:96)

at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:892)

at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:96)

at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)

at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:919)

at

這是我的實(shí)施:

CustomEditText

class CustomEditText @JvmOverloads constructor(

context: Context,attrs: AttributeSet? = null,defStyleAttr: Int = 0

) : LinearLayout(context,attrs,defStyleAttr) {

// ...

private lateinit var editText_input: EditText

private lateinit var textView_errorMessage: TextView

private var isErrorDisplayed = false

private var inputTextOriginalColor: ColorStateList? = null

init {

orientation = VERTICAL

clearContainerFormatting()

createEditTextInput(context,defStyleAttr)

createTextViewErrorMessage(context)

addView(editText_input)

addView(textView_errorMessage)

}

fun setError(message: String) {

//...

}

fun getText(): String = editText_input.text.toString()

fun setText(text: String) = editText_input.setText(text)

// ...

}

模型

data class SampleData(

private var _content: String

) : BaSEObservable() {

var content: String

@Bindable get() = _content

set(value) {

_content = value

notifyPropertyChanged(BR.content)

}

}

使用帶有數(shù)據(jù)綁定的CustomView的客戶端

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools">

name="data"

type="SampleData" />

name="presenter"

type="SamplePresenter" />

android:layout_width="match_parent"

android:layout_height="match_parent"

android:animateLayoutChanges="true"

tools:context=".sample_view.presentation.view.SampleView">

android:id="@+id/notificationPopup"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:clipToPadding="false"

android:elevation="4dp"

app:allowManualExit="true" />

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:gravity="center"

android:orientation="vertical">

android:id="@+id/textView_mirror"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:fontFamily="sans-serif"

android:text="@{data.content}"

android:textSize="16sp"

android:textStyle="bold"

tools:text="test" />

android:id="@+id/customEditText_sample"

style="@style/RegisterInput"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Type anything"

android:text="@={data.content}" />

android:id="@+id/button_validateInput"

style="@style/Widget.AppCompat.Button.Colored"

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_marginEnd="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

android:onClick='@{(v) -> presenter.onValidateDataClick(customEditTextSample.getText())}'

android:text="Validate Input" />

P.S.:如果我將CustomEditText替換為常規(guī)的EditText小部件,它可以很好地工作

總結(jié)

以上是生活随笔為你收集整理的android 自定义属性 双向绑定,如何解决:“在使用自定义视图实现双向数据绑定时,找不到属性’android:text’”的getter?...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。