Android_EditTextInputKontrol输入选择_141030

来源:互联网 发布:知乎 女友 智障 编辑:程序博客网 时间:2024/06/04 19:57

本文只是,选用了5中控制EditText输入的方法

 不多说,贴代码:

  // MainActivity.java

package com.yline.edittextinputkontrol;import android.app.Activity;import android.os.Bundle;import android.text.method.DateKeyListener;import android.text.method.DigitsKeyListener;import android.text.method.MultiTapKeyListener;import android.text.method.QwertyKeyListener;import android.text.method.TextKeyListener;import android.view.Menu;import android.widget.EditText;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//允许输入带有正负符号和小数点的数字EditText editText1 = (EditText) findViewById(R.id.editText1);DigitsKeyListener digkl1 = DigitsKeyListener.getInstance(true, true);editText1.setKeyListener(digkl1);//只允许正整数,不允许小数点EditText editText2 = (EditText) findViewById(R.id.editText2);DigitsKeyListener digkl2 = DigitsKeyListener.getInstance();editText2.setKeyListener(digkl2);//只允许日期EditText editText3 = (EditText) findViewById(R.id.editText3);DateKeyListener digkl3 = new DateKeyListener();editText3.setKeyListener(digkl3);//允许12键小键盘布局的多点触摸EditText editText4 = (EditText) findViewById(R.id.editText4);MultiTapKeyListener multititapkl = new MultiTapKeyListener(TextKeyListener.Capitalize.WORDS, true);editText4.setKeyListener(multititapkl);//允许qwerty布局键盘输入EditText editText5 = (EditText) findViewById(R.id.editText5);QwertyKeyListener qkl = new QwertyKeyListener(TextKeyListener.Capitalize.SENTENCES, true);editText5.setKeyListener(qkl);}@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;}}

  // activity_main.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:paddingLeft="5dip" >        <TextView        android:id="@+id/textView1"        android:paddingTop="3dip"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/TV1" />    <EditText         android:id="@+id/editText1"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/>        <TextView        android:id="@+id/textView2"        android:paddingTop="3dip"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/TV2" />    <EditText         android:id="@+id/editText2"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/>        <TextView        android:id="@+id/textView3"        android:paddingTop="3dip"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/TV3" />    <EditText         android:id="@+id/editText3"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/>        <TextView        android:id="@+id/textView4"        android:paddingTop="3dip"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/TV4" />    <EditText         android:id="@+id/editText4"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/>        <TextView        android:id="@+id/textView5"        android:paddingTop="3dip"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/TV5" />    <EditText         android:id="@+id/editText5"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/>    </LinearLayout>
   // String,xml

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="app_name">EditTextInputKontrol</string>    <string name="hello_world">Hello world!</string>    <string name="action_settings">Settings</string>        <string name="TV1">ditits listener with signs and decimal points</string>    <string name="TV2">ditits listener without signs and decimal points</string>    <string name="TV3">data listener</string>    <string name="TV4">multitap listener</string>    <string name="TV5">qwerty listener</string></resources>
运行图:


本文代码下载:

http://pan.baidu.com/s/1nt1FuDb


0 0