zoukankan      html  css  js  c++  java
  • android源代码提示文本框还能输入多少个字符

    public class TestAndroidActivity extends Activity { 
        /** Called when the activity is first created. */ 
         
         Button clearbtn; 
         EditText et; 
         TextView tv; 
         final int MAX_LENGTH = 50; 
         int Rest_Length = MAX_LENGTH; 
         
        @Override 
        public void onCreate(Bundle savedInstanceState) { 
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.main); 
             
            //tv =(TextView)findViewById(R.); 
        tv=(TextView) this.findViewById(R.id.btn); 
            //tv=this.findViewById(R.) 
            et = (EditText) this.findViewById(R.id.bg); 
     
            et.addTextChangedListener(new TextWatcher() { 
                 
                public void onTextChanged(CharSequence s, int start, int before, int count) { 
                    if(Rest_Length>0){ 
                        Rest_Length = MAX_LENGTH - et.getText().length(); 
                    } 
                } 
                 
                public void beforeTextChanged(CharSequence s, int start, int count, 
                        int after) { 
                    tv.setText("还可以输入"+Rest_Length+"个字"); 
                     
                } 
                 
                public void afterTextChanged(Editable s) { 
                    tv.setText("还可以输入"+Rest_Length+"个字"); 
                } 
            }); 
     
            clearbtn = (Button)findViewById(R.id.btn); 
            clearbtn.setOnClickListener(new Button.OnClickListener() { 
                 
                public void onClick(View v) { 
                    et.setText(""); 
                    Rest_Length = MAX_LENGTH; 
                } 
            }); 
        } 
    } 

     

  • 相关阅读:
    经典排序之 计数排序
    经典算法 总结
    经典排序之 二路归并排序
    经典排序之 堆排序
    经典排序之 插入排序
    经典排序之 冒泡排序
    经典排序之 选择排序
    经典排序之 快速排序
    两个队列实现一个栈
    Java Web系列:JDBC 基础
  • 原文地址:https://www.cnblogs.com/umgsai/p/3908207.html
Copyright © 2011-2022 走看看