[英]How to set texts in android for Tablelayouts?
I'm trying to set some values to text views in a table layout, but I can't test it on my phone due to self-closing the app. 我正在尝试为表格布局中的文本视图设置一些值,但是由于自动关闭应用程序,因此无法在手机上对其进行测试。
My XML file is defined here: 我的XML文件在这里定义:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableAfc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1">
<TableRow
android:id="@+id/rowAf1"
>
<TextView
android:text="Litera"
android:singleLine="true"
android:id="@+id/tAf1"
android:padding="5dip" />
<TextView
android:text="Pozitie initiala"
android:singleLine="true"
android:id="@+id/tAf2"
android:gravity="center"
android:padding="5dip" />
<TextView
android:text="Pozitie mediana"
android:id="@+id/tAf3"
android:singleLine="true"
android:gravity="center"
android:padding="5dip" />
<TextView
android:text="Pozitie finala"
android:singleLine="true"
android:id="@+id/tAf4"
android:gravity="center"
android:padding="5dip" />
</TableRow>
</TableLayout>
My java code... 我的Java代码...
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.cons_africate);
TextView t1= (TextView) super.findViewById(R.id.tAf1);
t1.setText(1);
}
If I don't try to change the text in the java code, it works, but with those two lines it crashes... 如果我不尝试更改Java代码中的文本,则可以正常工作,但是由于这两行而导致崩溃...
t1.setText(1);
does not work because setText()
only accept CharSquence type. 不起作用,因为
setText()
仅接受CharSquence类型。 So use t1.setText("1");
因此,使用
t1.setText("1");
在settext中使用倒置逗号,即“ 1”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.