如何在Android TextView中压缩文本?
我想在Android中合成两个文本并用单个文本视图显示。我试过下面的类型。它仅在logcat中显示,但在XMLTextView中不是concat 这是我的密码:如何在Android TextView中压缩文本?,android,textview,Android,Textview,我想在Android中合成两个文本并用单个文本视图显示。我试过下面的类型。它仅在logcat中显示,但在XMLTextView中不是concat 这是我的密码: <TextView android:id="@+id/heizgriffe" android:layout_width="wrap_content" android:layout_height="wrap_content"
<TextView
android:id="@+id/heizgriffe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heizgriffe"
android:textColor="#000"
android:textSize="12dp"
android:textStyle="bold"
android:layout_below="@+id/txt"/>
这里有什么问题吗?试试这个答案
txtConcat = (TextView)findViewById(R.id.txt); // initialize
String hub="Hubraum:";
String str= ItemList.getTxt(); // fetching from webservice
txtConcat .setText(hub + str );
String hub="Hubraum:";
String str= hub+ItemList.getTxt(); // fetcting from webservice
txtConcat.setText(str );
试试这个txtcontcat=(TextView)findViewById(R.id.txt)
难道不是:
txtcontcat=(TextView)findViewById(R.id.heizgriffe) 你想要做的事情并不像你看到的那么复杂,你得到的结果确实不是你想要的,看看你的代码,我可以说,即使是程序也不应该编译,因为它一定是在生成语法错误。这是因为无法使用setText连接文本。解决方案如下所示 XML文件:
<TextView
android:id="@+id/tvInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
结果如下:
我的身份证号码是:8945213624
您的代码没有问题,您只需正确使用连接的元素,在本例中,我显示我使用append来连接元素。很抱歉,我只是这样使用,但它不是concatstring concatenate,它在相对布局中工作正常,但在线性布局下不工作。有人知道这个问题的原因吗?现在它起作用了,这里我错误地将txtcontcat.setText()分为两次,所以只有这一次它不起作用
String str= (String) ItemList.getTxt();
<TextView
android:id="@+id/tvInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
public TextView tvInfo;
private java.lang.CharSequence ID = "8945213624";
TextView tvInfo = (TextView)findViewById(R.id.tvInfo);
tvInfo.setText("My ID number is: ");
tvInfo.append(ID);