Android应用程序Click事件与Touch事件处理
来源:互联网 发布:wordpress php页面 编辑:程序博客网 时间:2024/05/16 00:42
一、Click事件与Touch事件的区别:
Click事件:对于Button,既会响应按键,也会响应触摸屏事件;
Touch事件:对于Button,只响应触摸屏事件;
因此通常对于Button控件,最好用Click事件处理。
二、Click事件处理模板
import android.view.View.OnClickListener;
public class xxxx Activityextends Activity
{
private OnClickListener otl_conn = (OnClickListener) new ClickListenerConn();
private Button bv = null;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.xxxx);
bv = (Button) findViewById(R.id.xxxxbutton);
bv.setOnClickListener(otl_conn);
}
class ClickListenerConn implements OnClickListener
{
public void onClick(View v) {
xxxxxx......
}
}
}
layout/xxxx.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#FFF">
<Button android:id="@+id/connbutton"
android:text="connect"
android:textColor="#000"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
三、Touch事件处理模板
import android.view.View.OnTouchListener;
public class xxxx Activityextends Activity
{
private OnTouchListener otl_conn = (OnTouchListener) new TouchListenerConn();
private Button bv = null;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.xxxx);
bv = (Button) findViewById(R.id.xxxxbutton);
bv.setOnTouchListener(otl_conn);
}
class TouchListenerConn implements OnTouchListener
{
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
xxxx....;
break;
}
return true;
}
}
}
layout/xxxx.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#FFF">
<Button android:id="@+id/connbutton"
android:text="connect"
android:textColor="#000"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
四、Click事件处理另一精简模板
import android.view.View.OnClickListener;
public class xxxx Activityextends Activity implements View.OnClickListener
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.xxxx);
findViewById(R.id.connbutton).setOnClickListener(this);
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.connbutton:
xxxxxx......
break;
}
}
}
转载请注明出处:http://blog.csdn.net/ccwwff/archive/2010/08/18/5821419.aspx
- Android应用程序Click事件与Touch事件处理
- touch事件与click事件
- android touch事件处理
- android touch事件处理
- Android Touch事件处理
- 关于click事件与touch事件冲突的问题
- tap,touch,touchstart事件与click事件的区别
- 移动前端—touch事件与click事件的区别
- Android touch事件、click事件、focus、selected的区别
- Android: Android Touch事件处理
- Android Touch事件处理机制
- Android touch事件处理流程
- Android中的Touch事件处理
- Android中的Touch事件处理
- Android中的Touch事件处理
- Android的Touch事件处理
- Android Touch事件处理机制
- Android中的Touch事件处理
- 手机移动办公,不再遥不可及
- vs2005编程环境下无法使用查找功能的解决办法【转】
- red-hat5下安装firefox遇到的问题
- Java正则表达式详解
- patch文件的执行和制作
- Android应用程序Click事件与Touch事件处理
- 关于Makefile
- 第一次......
- 实训之心得体会
- 汇编语言
- Java JTable设置列宽实现表格不等宽
- Why uses ZOPE
- 浏览器缓存问题
- 实现永久性注册表数据保存(VIACEPC BSP)