在android 中利用button 按钮设置监听事件
来源:互联网 发布:php文章评论代码 编辑:程序博客网 时间:2024/06/08 07:16
新建一个空工程,然后当你点击button 按钮时,会提示你
<span style="color:#ff0000;">"TextView里的文字发生了改变,你注意到了吗?", </span>
在android 中利用button 按钮设置监听事件
package com.example.androidtest;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.widget.Button;import android.widget.Toast;import android.view.View;import android.widget.TextView; import android.view.View.OnClickListener;public class MainActivity extends Activity {private TextView textview1; private Button button1; @Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main); textview1 = (TextView)findViewById(R.id.textView1); button1 = (Button)findViewById(R.id.button1); button1=(Button)findViewById(R.id.button1); //增加事件响应 button1.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { //Toast提示控件 Toast.makeText(MainActivity.this, "TextView里的文字发生了改变,你注意到了吗?", Toast.LENGTH_LONG).show(); //将TextView的文字发生改变 textview1.setText("欢迎你 前辈"); // textview1.setText("你好,前辈"); } }); }@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
XML中的配置文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_marginTop="87dp" android:layout_toRightOf="@+id/textView1" android:text="Button test" /> </RelativeLayout>
0 0
- 在android 中利用button 按钮设置监听事件
- Android中设置按钮监听事件
- android中ListView中在Adapter中为Button设置监听事件方法--跳转Activity
- android开发中Button按钮监听事件(匿名内部类监听或者不匿名)
- 【Button】按钮onTouch事件监听
- Android actionbar右上角按钮设置监听事件
- android listview中按钮事件监听问题
- Android中按钮的点击事件监听
- Android按钮事件监听
- unity3D 在UGUI中动态添加button的监听事件
- Android Button click 事件监听
- android button双击监听事件
- Android开发-button监听事件
- Android 在xml布局配置文件中给Button按钮添加事件
- android 中 Button 的监听事件的多种实现方式
- android设置软件按钮为“搜索”,并监听事件
- Android 自定义Dialog类,并在Activity中实现按钮监听事件
- android:onClick 设置Button监听
- 设计模式学习03—抽象工厂模式
- 2014WWDC发布会的解读
- chrome查看手机版网页
- 100%托管代码自定义服务器控件ASP.NET Barcode Web Server Control
- HTTP hijack
- 在android 中利用button 按钮设置监听事件
- Java创建线程的两个方法
- 大数相加问题
- understand licenses by one picture
- HDU 1166 敌兵布阵 Segment Tree题解
- 有用软件
- Python中线程池的实现
- Hash碰撞导致的denial of service
- OPPO find5(X909)Omni刷机包 原生安卓4.4.2 超流畅省电