EditTextDemo.java
package com.example.demo;
import android.app.Activity; import android.os.Bundle; import android.text.InputFilter; import android.widget.EditText;
public class EditTextDemo extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edit_demo); EditText text_filtered = (EditText)findViewById(R.id.input_filered); text_filtered.setFilters(new InputFilter[] { new InputFilter.AllCaps(), //소문자로 입력된 값을 대문자로 바꿔줌 new InputFilter.LengthFilter(2) //최대 2글자만 입력가능.. }); } }
--------------------------------------------------------------------------------------------------
edit_demo.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout android:id="@+id/linear02" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="type here" android:lines="4" /> //4줄까지만 보임...
<EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="preset value" android:editable="false" /> //내용을 바꿀수 없음... <EditText android:id="@+id/input_filered" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="type here" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="숫자만 입력 가능합니다" android:inputType="number" /> //숫자만 입력 가능함...
<EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="비밀번호를 입력하세요" android:password="true" /> //비밀번호 입력 EditText </LinearLayout>
</ScrollView> |