由网友(学会抛开过去)分享简介:我试图改变从code我的的TextView 文本。I'm trying to change my TextView text from the code.这是我的XML是这样的:This is what my xml looks like:XML:我试图改变从code我的
的TextView
文本。
I'm trying to change my TextView
text from the code.
这是我的XML是这样的:
This is what my xml looks like:
XML:
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal" />
而code:
And the code:
TextView tv1 = (TextView)findViewById(R.id.textView1);
tv1.setText("Hello");
setContentView(tv1);
我在我的设备上得到一个错误,应用程序停止。
我试图表明一个的TextView
(未连接到一个XML 的TextView
)和它的工作。
I'm getting an error on my device and the application stops.
I tried to show a TextView
(not connected to an XML TextView
) and it worked.
推荐答案
您的做法是不正确。我认为这将是空指针异常。更好地发布日志猫
Your approach is incorrect. I think it will be Null Pointer Exception. Better to post log cat
正确的位置
setContentView(R.layout.yourlayout):
在此行应指定要使用的布局。
In this line you should specify the layout you are using.
然后
TextView tv1 = (TextView)findViewById(R.id.textView1);
tv1.setText("Hello");
研究这里它到底是什么,你想要要知道
Study here It is what exactly you want to know
相关推荐
最新文章