5

I created app using retrofit callback. In that i wanna show some information with text. In textView i already binded the data, also i need to concat some texts along with that.

My Code Follows

View:

<?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>

Model:

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;
    }
}

Expected Output:

Model Return + "Concat String"

1
  • You literally wrote the answer as the last sentence of your question.... Just add + "your string" to the end of your getxxx() method Commented Mar 21, 2017 at 11:09

2 Answers 2

3

Try this Simple Way

All your processing things and Business Logic should be in Controller Class (i.e: ViewModel in MVVM)

write one method in Controller, pass the value to Controller, then that method returns the value with Concat String

Code Sample

android:text="@{Controller.getUserProfile(UserProfile.username)}"

Controller Method

public String getUserProfile(String name)
{
     return name + "concat string";
}
Sign up to request clarification or add additional context in comments.

Comments

3

concat it in xml

android:text="@{UserProfile.username + `Concat String`}"

3 Comments

Nice, but when you get the value from TextView or EditText.. it will return with concat string
@Keerthivasan OP didn't clerify those things in question, OP just wants to concat the string, so i have given a simplest way :)
yeah.. i accept that. thats why i puts up vote for your answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.