2012-04-30 19 views

回答

2

這是XML容易。 這是我們如何做這個java文件。

EditText et = new EditText(context);      
// setting input type filter   
et.setInputType(InputType.TYPE_CLASS_NUMBER);      
// setting input max length 
InputFilter maxLengthFilter = new InputFilter.LengthFilter(inp.getLength()); 
et.setFilters((new InputFilter[]{ maxLengthFilter })); 
// settin it to password 
et.setTransformationMethod(PasswordTransformationMethod.getInstance()); 
0

我在XML做到了這一點,只是在<EditText />

添加

android:numeric="decimal

0

這樣做:

LinearLayout mLinearLayout = new LinearLayout(this); 
mLinearLayout = (LinearLayout)findViewById(R.id.mylinearlayout); 

Button lButton = (Button)findViewById(R.id.mybtnid); 
lButton.setOnClickListener(new View.OnClickListener() { 
public void onClick(View arg0) { 
    EditText lEditText = new EditText(this); 
    lEditText .setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 
             LayoutParams.WRAP_CONTENT)); 
    lEditText.SetText("Text Here"); 
    mLinearLayout.addView(lEditText); 

EditorInfo ed = new EditorInfo(); 
ed.inputType = InputType.TYPE_CLASS_PHONE;       
lEditText.setInputType(ed.inputType); 

InputFilter[] FilterArray = new InputFilter[1]; 
FilterArray[0] = new InputFilter.LengthFilter(6); 
lEditText.setFilters(FilterArray); 

或查看blog的限制最大長度

阿迪亞答案有方法的密碼,我認爲這是更好

問候