android > EditText 控件操作

* EditText 自动换行

<EditText 
    android:layout_width="0dip"
    android:layout_height="120dip"
    android:layout_margin="10dip"  
    android:scrollbars="vertical"
    android:scrollbarAlwaysDrawVerticalTrack="true"
    android:gravity="top"
    android:inputType="textCapSentences|textMultiLine"
    android:textColor="#000000" 
    />

* EditText 密码显示/隐藏

if(pass_show.isChecked()){
	//显示明文
	pass.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
}else{
	//显示密码
	pass.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}

* 监听EditText 发生变化

public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
          
        text = (EditText)findViewById(R.id.text);  
        text.addTextChangedListener(textWatcher);  
    }  
      
    private TextWatcher textWatcher = new TextWatcher() {  
          
        @Override    
        public void afterTextChanged(Editable s) {     
            // TODO Auto-generated method stub     
            Log.d("TAG","afterTextChanged--------------->");   
        }   
          
        @Override 
        public void beforeTextChanged(CharSequence s, int start, int count,  
                int after) {  
            // TODO Auto-generated method stub  
            Log.d("TAG","beforeTextChanged--------------->");  
        }  
 
         @Override    
        public void onTextChanged(CharSequence s, int start, int before,     
                int count) {     
            Log.d("TAG","onTextChanged--------------->");    
            str = text.getText().toString();  
            try {  
                //if ((heighText.getText().toString())!=null)   
                Integer.parseInt(str);  
                  
            } catch (Exception e) {  
                // TODO: handle exception  
                showDialog();  
            }  
                              
        }                    
    };

* 默认不获取焦点

在EditText 父级 加属性

android:focusable="true"   
android:focusableInTouchMode="true"

相关推荐