Android - 我可以将 EditText 值添加到 Activity_main 中 TextView 的 android:text 行并将其连接起来吗?

问题描述 投票:0回答:1
<EditText
    android:id="@+id/et_name"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:layout_margin="20dp"
    android:hint="@string/str_name" />

<TextView
    android:id="@+id/tvSentence"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:text="@string/str_hello1"/>

我希望将 et_name 添加到 @string/str_hello1 行。我试过这个:

<TextView
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:text="@string/str_hello1"  + "@+id/et_name"

    android:text="@string/str_hello1"  + et_name

    android:text="@string/str_hello1"  + "et_name"

但是它们都不起作用,现在所有内容都用红色下划线表示意外的文本。

android android-activity program-entry-point string-concatenation
1个回答
0
投票

你必须以编程方式从 java 端或 kotlin 中完成它,你不能在 xml 中做到这一点

© www.soinside.com 2019 - 2024. All rights reserved.