【发布时间】:2017-03-21 11:06:07
【问题描述】:
我使用改造回调创建了应用程序。在那我想用文字显示一些信息。在 textView 中我已经绑定了数据,我还需要连接一些文本。
我的代码如下
查看:
<?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>
<variable
name="UserProfile"
type="com.practical_session.sai.instaprouser.Profile.model.UserProfileInfo" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linear"
android:orientation="vertical"
android:background="@drawable/animation_list"
tools:context="com.practical_session.sai.instaprouser.Profile.view.ProfileActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/imageView"
android:layout_marginLeft="10dp"
android:layout_marginTop="8dp"
android:textSize="20dp"
android:text="@{UserProfile.username}"
android:textColor="@android:color/black" />
</RelativeLayout>
</LinearLayout>
</layout>
型号:
public class UserProfileInfo extends BaseObservable {
@SerializedName("username")
@Expose
private String username;
@Bindable
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
预期输出:
模型返回+“连接字符串”
【问题讨论】:
-
你确实把答案写成了你问题的最后一句话......只需在你的 getxxx() 方法的末尾添加 +“你的字符串”
标签: android mvvm android-databinding