简单页面,不一一介绍,直接上源码
`
package cn.npe1348.zfbpay.view;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import cn.npe1348.zfbpay.R;

public class PasswordView extends RelativeLayout {
private Context context;
// 输入的密码
private String strPassword;
// 就6个输入框不会变了,用数组内存申请固定空间,比List省空间
private TextView[]textViewList;
// 用GrideView布局键盘,其实并不是真正的键盘,只是模拟键盘的功能
private GridView gridView;
// 要用Adapter中适配,用数组不能往adapter中填充
private ArrayList> valueList;
//取消按钮
private ImageView tvCancel;
//忘记密码按钮
private TextView tvForget;
// 用于记录当前输入密码格位置
private int currentIndex = -1;

//自定义接口public interface OnPasswordInputFinish {    //添加密码输入完成的接口    void inputFinish();    //取消支付接口    void outfo();    //忘记密码接口    void forgetPwd();}public PasswordView(Context context, AttributeSet attrs) {    this(context, attrs,0);}public PasswordView(Context context, AttributeSet attrs, int defStyleAttr) {    super(context, attrs, defStyleAttr);    this.context = context;    //view布局    View view = View.inflate(context, R.layout.layout_popup_bottom, null);    valueList = new ArrayList>();    textViewList = new TextView[6];    //初始化控件    tvCancel=(ImageView) view.findViewById(R.id.tvCancel);    tvForget = (TextView) view.findViewById(R.id.tv_forgetPwd);    textViewList[0] = (TextView) view.findViewById(R.id.tv_pass1);    textViewList[1] = (TextView) view.findViewById(R.id.tv_pass2);    textViewList[2] = (TextView) view.findViewById(R.id.tv_pass3);    textViewList[3] = (TextView) view.findViewById(R.id.tv_pass4);    textViewList[4] = (TextView) view.findViewById(R.id.tv_pass5);    textViewList[5] = (TextView) view.findViewById(R.id.tv_pass6);    //初始化键盘    gridView = (GridView) view.findViewById(R.id.gv_keybord);    //设置键盘显示按钮到集合    setView();    // 必须要,不然不显示控件    addView(view);}//设置按钮显示内容private void setView() {    // 初始化按钮上应该显示的数字    for (int i = 1; i < 13; i++) {        Map map = new HashMap();        if (i < 10) {            map.put("name", String.valueOf(i));        } else if (i == 10) {            map.put("name", "X");        } else if (i == 12) {            map.put("name", "<");        } else if (i == 11) {            map.put("name", String.valueOf(0));        }        valueList.add(map);    }    //为键盘gridview设置适配器    gridView.setAdapter(adapter);    //为键盘按键添加点击事件    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {        @Override        public void onItemClick(AdapterView<?> parent, View view,                                int position, long id) {            // 点击0~9按钮            if (position < 11 && position != 9) {                // 判断输入位置————要小心数组越界                if (currentIndex >= -1 && currentIndex < 5) {                    textViewList[++currentIndex].setText(valueList.get(position)                            .get("name"));                }            } else {                // 点击退格键                if (position == 11) {                    // 判断是否删除完毕————要小心数组越界                    if (currentIndex - 1 >= -1) {                        textViewList[currentIndex--].setText("");                    }                }else if(position == 9){                    currentIndex = -1;                    for(int i = 0,length=textViewList.length;i

}

`

更多相关文章

  1. Android(安卓)在线升级APK
  2. android创立输入对话框
  3. android 进度对话框 圈
  4. Android(安卓)两种方式优雅实现按钮防重复点击,防抖功能
  5. android EditText 不自动弹出键盘的方法
  6. Android中EditText的焦点改变处理
  7. Android中的Selector的使用
  8. Android适配底部虚拟键盘遮挡布局的解决方案
  9. 《Android(安卓)基础(十二)》 TextInputLayout,让输入框更有灵性

随机推荐

  1. android app 缓存 ---- android 文件缓存
  2. 如何在Android上显示wmf的文件
  3. Android(安卓)中Message,MessageQueue,Lo
  4. 【Android增量升级系列_02】 浅谈Android
  5. Android之Weight属性源码解析
  6. android蜂巢效果、环形菜单、Kotlin影视
  7. 深入了解Android(安卓)任务和进程
  8. 小米:最快11月底或12月初推出 Android 4.0
  9. Android使用AsyncTask下载显示图片
  10. Android的备份服务概述