1.效果图:

(1)MainAcivity.java

 package com.example.app3;

 import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView; public class MainActivity extends AppCompatActivity {
private EditText editText;
private TextView textView; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); editText = (EditText) findViewById(R.id.et);
textView = (TextView) findViewById(R.id.tv_show); editText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
editText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch (event.getAction()){
case KeyEvent.ACTION_UP:
String info = editText.getText().toString();
textView.setText("您输入的银行卡号是:"+subs(info));
case KeyEvent.ACTION_DOWN:
break;
}
return false;
}
});
return false;
}
}); } public String subs(String info){
String mess="";
for(int i =0;i<=info.length()/4;i++){
if(i*4+4<info.length()){
mess=mess+info.substring(i*4,i*4+4)+" ";
}else{
mess=mess+info.substring(i*4,info.length());
}
}
return mess;
}
}

2.acivity_mian.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="com.example.app3.MainActivity"
android:orientation="vertical"> <EditText
android:id="@+id/et"
android:hint="请输入您的银行卡号"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>

触摸事件onTouchListener的更多相关文章

  1. Android 手势&amp;触摸事件 MotionEvent

    1.http://blog.csdn.net/omg_2012/article/details/7881443 这篇相当好啊 2.http://blog.csdn.net/android_tutor/ ...

  2. Android 手势&触摸事件

    在刚开始学Android的时候,就觉得Google的文档不咋样,在研究手势时,更加的感觉Google的文档写得实在是太差了.很多常量,属性和方法,居然连个描述都没有. 没有描述也就罢了,但是OnGes ...

  3. 一个demo让你彻底理解Android触摸事件的并发

    注:本文涉及的demo的地址:https://github.com/absfree/TouchDispatch 1. 触摸动作及事件序列 (1)触摸事件的动作 触摸动作一共有三种:ACTION_DOW ...

  4. 对于android触摸事件模型的一些理解

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  5. 触摸事件 Touch MotionEvent ACTION

    MotionEvent简介 当用户触摸屏幕时,将创建一个MontionEvent对象,MotionEvent包含了关于发生触摸的位置.时间信息,以及触摸事件的其他细节. 获取MontionEvent对 ...

  6. 一步一步学android之事件篇——触摸事件

    触摸事件顾名思义就是触摸手机屏幕触发的事件,当用户触摸添加了触摸事件的View时,就是执行OnTouch()方法进行处理,下面通过一个动态获取坐标的例子来学习OnTouchListener事件,效果如 ...

  7. android 组件内部实现触摸事件,更改背景

    当我们需要实现触摸事件的时候,通常就会想到OnTouchEvent这个方法,它能够获取触摸点的坐标,而组件同样也有这样的一个功能,使用这个功能,可以实现组件在父布局界面上移动,缩放,更改背景图片.这里 ...

  8. 初识Android触摸事件传递机制

    前言 今天总结的一个知识点是Andorid中View事件传递机制,也是核心知识点,相信很多开发者在面对这个问题时候会觉得困惑,另外,View的另外一个难题滑动冲突,比如在ScrollView中嵌套Li ...

  9. Android触摸事件(一)-TouchEventHelper

    文件夹 文件夹 概述 关于更新 2016-08-31 2016-06-20 关于单点触摸事件singleTouch 单击的两种方式 关于双击事件 双击事件的检測逻辑 双击事件触发的时机 关于多点触摸事 ...

随机推荐

  1. idea xml 绿背景色 去掉拼写检查

    去掉背景色 去掉拼写检查

  2. How do I use EC2 Systems Manager to join an instance to my AWS Directory Service domain?

    1. Create new role "EC2RoleforSSM" in AWS IAM AWS->IAM->Roles->Create role->Se ...

  3. java md5加密 不依赖base64包

    /** * MD5 加密 */ private String getMD5Str(String str) { MessageDigest messageDigest = null; try { mes ...

  4. CodeSmith和PowerDesigner (转)

    首先,既然要讲解如何使用CodeSmith和PowerDesigner快速生成批量代码,当然要先安装这2个软件啦,下面就简单说说如何安装破解这2款软件吧,当然破解只是学习之用,请大家不要用于商业用途哈 ...

  5. oracle12c创建用户等问题

    一:前言 这几天我重新装了下电脑,然后自己有试着去装了下oracle11g,结果还是失败了然后我自己又去下载了最新的oracle12c,oracle12c中有两个用户sys和system,scott已 ...

  6. 【BZOJ2460】【BJOI2011】元素 [线性基]

    元素 Time Limit: 20 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 相传,在远古时期,位于西方大陆的 Ma ...

  7. 51nod 1254 最大子段和 V2 ——单调栈

    N个整数组成的序列a[1],a[2],a[3],…,a[n],你可以对数组中的一对元素进行交换,并且交换后求a[1]至a[n]的最大子段和,所能得到的结果是所有交换中最大的.当所给的整数均为负数时和为 ...

  8. bzoj 1576: [Usaco2009 Jan]安全路经Travel——并查集+dijkstra

    Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第i行包含一个数 ...

  9. 1、使用Xcode修改iOS项目工程名和路径名

    http://blog.sina.com.cn/s/blog_a42013280101blxo.html 对,好:错,改正. ------ 前言 系统 10.7 狮子 开发平台 xcode 4.5.2 ...

  10. Kuangbin 带你飞-线段树专题 题解

    HDU 1166 敌兵布阵 单调更新区间查询和 #include <map> #include <set> #include <list> #include < ...