欢迎使用CSDN-markdown编辑器

来源:互联网 发布:华为软件开发面试经验 编辑:程序博客网 时间:2024/06/04 00:23

1.修改activity_main.xml中Button的属性,为按钮增加单击事件请求。修改的xml文件如下:

<Button    android:id="@+id/button1"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_alignParentRight="true"    android:layout_below="@+id/textView1"    android:layout_marginRight="58dp"    android:layout_marginTop="88dp"    android:onClick="OnButton1"    android:text="Button" />

2.在java文件中增加xml文件中提到的OnButton1函数:

public void OnButton1(View v){ final TextView text = (TextView) findViewById(R.id.textView1); text.setText("Hello, World !. " + " ....");    }

如下编码效果:
这里写图片描述

0 0
原创粉丝点击