让TextView中可见由pressing一个按钮 [英] Make Textview Visible by Pressing a Button
本文介绍了让TextView中可见由pressing一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Android应用程序编程我的第一课堂作业,希望你们能帮助做到这一点。
I have my first class assignment in android app programming, hopefully you guys could help with this.
我需要一个code连接到一个按钮,所以当我preSS是我的TextView会出现。
I need to connect a code to a button so when I press it my textview will appear.
在我的XML文件我有
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="22dp"
android:text="@string/ok_knappen"
android:textColor="@color/button_dark_text"
android:onClick="b"
/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignLeft="@+id/textView2"
android:layout_marginBottom="15dp"
android:text="@string/Beskrivning"
android:visibility="invisible" />
在我的活动我有
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t=(TextView)findViewById(R.id.textView3);
Button b= (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
t.setVisibility(View.VISIBLE);
}
});
}
没有出现错误。我的文字是invisbile但是当我按一下按钮没有任何反应。什么是错的?
No errors occurred. My text is invisbile but when I click the button nothing happens. What is wrong?
推荐答案
在TextView中添加:
In TextView add:
android:visibility="invisible"
在Java的code:
In Java code:
public void b(View view) {
EditText numerField = (EditText) findViewById(R.id.button1);
TextView tex = (TextView) findViewById(R.id.textView2);
tex.setVisibility(View.VISIBLE);
//do sth
}
这篇关于让TextView中可见由pressing一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文