0

I need to concatenate two string and display with single text view. That string concatenate is working fine within Relative Layout. But i want to concatenate within Linear layout.

Here my code:

<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/l1"
    android:id="@+id/ll"
    android:orientation="vertical"
>
    <TextView
        android:id="@+id/hubraum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp" 
        android:text="Hubraum :"
        android:textColor="#000"
        android:textSize="12dp" 
        android:layout_gravity="left"
    />
</LinearLayout>

.java

String title  = "Hubraum: ";
String value  = bikeItemList.getHubraum();
String result = title + value;          
txtCapacity.setText(result);

I tried the above type and following type also

txtCapacity.setText("Hubraum: " +","+ bikeItemList.getHubraum());

But it only display bikeItemList.getHubraum(). the "Hubraum:" is not display.

I tried with using append also but it display bikeItemList.getHubraum() this text only.

Any one can know the reason.

2
  • what is bikeItemList? Is it List? getHubraum returns what type? Please specify this things Commented Mar 13, 2012 at 4:43
  • yes, bike item list is an ArrayList Commented Mar 13, 2012 at 5:37

5 Answers 5

1

StringBuilder b = new StringBuilder(128);

b.append(title).append(value);

b.toString();

Sign up to request clarification or add additional context in comments.

Comments

0

Please try following way,

String str = "Hubraum: " +","+ bikeItemList.getHubraum().toString();
txtCapacity.setText(str);

2 Comments

where is txtCapacity in your xml ?
txtCapacity in my java code txtCapacity = (TextView)findViewById(R.id.hubraum);
0

Just use append properties of tectview for only value bcz title is already you have given in xml

    String title="Hubraum: ";
    String value = bikeItemList.getHubraum().toString();
    txtCapacity.append(value);

Comments

0

Check to see if it is called from the UIThread, also you can try

txtCapacity.invalidate();

to force a refresh/redraw.

There's also a chance that your Java code is not called at all, try change the default text from

android:text="Hubraum :"

to something else, and see if it's the default text that's being shown.

Comments

0

You can also use StringBuffer and append the string. display txtCapacity.setText(strbuf.toString());

Comments

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.