1、直接在控件定义里面进行赋值(不推荐),如下以显示一个TextView控件为例,其他类似
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="我的第一个工程,嘻嘻!"
android:textAppearance="?android:attr/textAppearanceMedium" />
2、在主程序里面调用findViewById来进行
TextView text = (TextView) super.findViewById(R.id.textView1);
text.setText("我的第一个Android程序!");
3、在strings里面进行定义,然后在主程序里面使用findViewById来进行调用
<string name="user_name_string">我的第一个工程,嘻嘻!</string>
TextView text = (TextView) super.findViewById(R.id.textView1);
text.setText(R.string.user_name_string);
4、在strings里面进行定义,然后在控件定义里面用@string/xxxxx (推荐使用)
<string name="user_name_string">我的第一个工程,嘻嘻!</string>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="@string/user_passward_string"
android:textAppearance="?android:attr/textAppearanceMedium" />
5、不使用布局管理器,使用context类创建,先在strings中定义
<string name="user_name_string">我的第一个工程,嘻嘻!</string>
TextView text = new TextView(this);
text.setText(super.getString(R.string.user_name_string));
setContentView(text);