Android:在EditText中达到最大字符时的新活动

时间:2014-03-27 14:40:50

标签: java android xml eclipse xml-layout

我有这个编辑文字:

<EditText
    android:id="@+id/editTextNew"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="50dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="50dp"
    android:padding="25dp"
    android:maxLength="200"
    android:gravity="top|left"
    android:background="#fff"
    android:lineSpacingMultiplier="1.5"
    android:inputType="textMultiLine|textCapSentences" >
</EditText>

它最多有200个字符,我怎么能这样做,这样当输入最后一个字符时,屏幕会淡出,然后是一个&#34;下一个按钮&#34;出现?

1 个答案:

答案 0 :(得分:0)

如果已达到最大字符数,您可以使用Textwatcher在文本更改后确定。

试试这段代码:

 EditText yourEditText = (EditText)findViewById(R.id.editTextNew);

 yourEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {}
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,int after) {}

        @Override
        public void afterTextChanged(Editable s) {
            if(s.length() >= 200){
                // Show your Button now ...
            }
        }
    });