qwerty.xml内容
源码下载地址:http://download.csdn.net/detail/hfsu0419/4534209
上方出处:http://blog.csdn.net/hfsu0419/article/details/7924673
下文出自:http://qsyz2002.blog.163.com/blog/static/7216669201110155051470/
先上图吧:
<?xml version="1.0" encoding="utf-8"?> <!-- 投放优惠券 --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/toufang_bg"> <TextView android:layout_width="wrap_content" android:textColor="#000000" android:textSize="35px" android:textStyle="bold" android:layout_height="wrap_content" android:text="手机号:" /> <EditText android:id="@+id/phone" android:layout_width="400px" android:textSize="30px" android:layout_height="wrap_content" android:hint="请填写要投放的手机号" /> <LinearLayout android:layout_width="fill_parent" android:layout_margin="10px" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center_horizontal"> <Button android:id="@+id/one" android:layout_width="wrap_content" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:background="@drawable/number_btn" android:layout_weight="1" android:layout_height="wrap_content" android:text="1" /> <Button android:id="@+id/two" android:layout_weight="1" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:background="@drawable/number_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2" /> <Button android:id="@+id/three" android:layout_weight="1" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:background="@drawable/number_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_margin="10px" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center_horizontal"> <Button android:id="@+id/four" android:layout_width="wrap_content" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:background="@drawable/number_btn" android:layout_weight="1" android:layout_height="wrap_content" android:text="4" /> <Button android:id="@+id/five" android:layout_weight="1" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:background="@drawable/number_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="5" /> <Button android:id="@+id/six" android:layout_weight="1" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:background="@drawable/number_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="6" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_margin="10px" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center_horizontal"> <Button android:id="@+id/seven" android:layout_width="wrap_content" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:background="@drawable/number_btn" android:layout_weight="1" android:layout_height="wrap_content" android:text="7" /> <Button android:id="@+id/eight" android:layout_weight="1" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:background="@drawable/number_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="8" /> <Button android:id="@+id/night" android:layout_weight="1" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:background="@drawable/number_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="9" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_margin="10px" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center_horizontal"> <Button android:id="@+id/zero" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content" android:text="0" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:background="@drawable/number_btn" /> <Button android:id="@+id/reset" android:layout_weight="1" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:text="重 置" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/number_btn" /> <Button android:id="@+id/delete" android:layout_weight="1" android:textSize="20px" android:textColor="#ffffff" android:textStyle="bold" android:text="删 除" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/number_btn" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_marginTop="10px" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center_horizontal"> <Button android:id="@+id/confirm" android:background="@drawable/toufang_btn" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/cancle" android:background="@drawable/cancle_btn" android:layout_weight="1" android:layout_marginLeft="15px" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
Activity:就贴一些关键的代码吧private StringBuffer sb;//用来存放输入数字的sb,呵呵
private EditText phone;//电话号码输入
phone = (EditText) findViewById(R.id.phone); phone.setFocusable(false);//不让该edittext获得焦点 phone.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { phone.setInputType(InputType.TYPE_NULL); // 关闭软键盘,这样当点击该edittext的时候,不会弹出系统自带的输入法 return false; } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.cancle: finish(); break; case R.id.confirm: String userTel = (String) phone.getText().toString(); if (userTel != null && !"".equals(userTel.toString().trim()) && !"null".equals(userTel.toString().trim().toLowerCase())) { if (loadingDialog == null) loadingDialog = AlertUtil .buildLoadingDialog(ToufangActivity.this); loadingDialog.show(); // 判断是否填写手机号 // String userTel = (String)phone.getText().toString(); sendCouponByTelHandler = new SendCouponByTelHandler(offer); if (userTel != null && !"".equals(userTel.toString().trim()) && !"null".equals(userTel.toString().trim() .toLowerCase())) { // 创建线程 (生成验证码+绑定验证码) if (match(userTel)) {// 验证手机号是否合法 new SendCouponByTelThread(offer, userTel).start(); } else { loadingDialog.dismiss(); AlertUtil.toast(ToufangActivity.this, R.drawable.dialog_err_icon, "请填写正确的手机号!"); sb.replace(0, sb.length(), ""); phone.setText(""); } } } else { AlertUtil.toast(ToufangActivity.this, R.drawable.dialog_err_icon, "请填写手机号!"); } break;
case R.id.one: sb.append(one.getText().toString().trim()); phone.setText(sb.toString().trim()); break; case R.id.two: sb.append(two.getText().toString().trim()); phone.setText(sb.toString().trim()); break; case R.id.three: sb.append(three.getText().toString().trim()); phone.setText(sb.toString().trim()); break; case R.id.four: sb.append(four.getText().toString().trim()); phone.setText(sb.toString().trim()); break; case R.id.five: sb.append(five.getText().toString().trim()); phone.setText(sb.toString().trim()); break; case R.id.six: sb.append(six.getText().toString().trim()); phone.setText(sb.toString().trim()); break; case R.id.seven: sb.append(seven.getText().toString().trim()); phone.setText(sb.toString().trim()); break; case R.id.eight: sb.append(eight.getText().toString().trim()); phone.setText(sb.toString().trim()); break; case R.id.night: sb.append(night.getText().toString().trim()); phone.setText(sb.toString().trim()); break; case R.id.zero: sb.append(zero.getText().toString().trim()); phone.setText(sb.toString().trim()); break; case R.id.delete: if (sb.length() - 1 >= 0) { sb.delete(sb.length() - 1, sb.length()); phone.setText(sb.toString().trim()); } break; case R.id.reset: sb.replace(0, sb.length(), ""); phone.setText(sb.toString().trim()); break; default: break; } }