我现在清理网络,但没有找到解决我这个问题的方法。
我的问题是我有一个TextView
,在其中我想使用android:text
属性显示文本。应根据运行的@string
,有条件地从FLAVOR
中获取此文本。
我将我的xml布局文件包装在<layout></layout>
标签中,并且在这些标签中,我导入了一些类:
<data>
<import type="esy.es.matmatt.pidroCounter.BuildConfig"/>
<import type="android.view.View"/>
</data>
要根据FLAVOR有条件地在Textview中显示不同的文本,我具有以下TextView:
<TextView
android:text="@{String.valueOf(BuildConfig.FLAVOR.equals(`free`) ? @string/about_text : @string/about_textPro)}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textViewFree"
android:layout_below="@+id/aboutTitle"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAlignment="center"
android:autoLink="email"
android:textColorLink="@color/textn"/>
我不知道为什么它只输出一个空白的TextView ...它什么都不显示...
我在this帖子中读到,在[[@之后应该有一个=符号,但是当我添加该符号时,我得到的只是一个编译错误:
M:\Git Repositories\PidroCounter\app\build\generated\ap_generated_sources\freeDebug\out\esy\es\matmatt\pidroCounter\DataBinderMapperImpl.java:10: error: cannot find symbol import esy.es.matmatt.pidroCounter.databinding.FragmentAboutBindingImpl;
^
我无法简单地找到错误。我使用的导入和条件语法在adview的可见性上似乎工作正常,但在TextViews上却根本不工作?我不知道我在做什么错。有任何想法吗?谢谢!编辑:实际上,我现在意识到条件在adviews(XML)中也不起作用。我以为是因为我也以编程方式有条件地加载
MobileAds
...
String.valueOf
而存在于您编写的绑定表达式中。应该是android:text="@{BuildConfig.FLAVOR.equals(`free`) ? @string/about_text : @string/about_textPro}"
[如果无法使用,请打开由数据绑定生成的BindingImpl.java
(例如:YourLayoutNameBindingImpl.java
)类。搜索您的视图ID(textViewFree
),并将生成的代码发布到此处。