我有一个edittext
限制为150个字符,当所有字符都被写入时,会出现一个按钮,让用户进入下一个活动,我这样做了:
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() >= 150){
bubble = (Button)findViewById(R.id.buttonSend);
bubble.setVisibility(View.VISIBLE);
Animation anim = AnimationUtils.loadAnimation(NewTextActivity.this, R.anim.push_left_in);
bubble.startAnimation(anim);
counter = (TextView)findViewById(R.id.textViewCount);
counter.setVisibility(View.GONE);
Animation anim2 = AnimationUtils.loadAnimation(NewTextActivity.this, R.anim.fade_out);
counter.startAnimation(anim2);
}}
}
);
我已将按钮的可见性设置为xml
,然后在写入150个字符时可见,并且效果很好,但我现在想要创建的是删除字符时,该按钮应该再次隐藏,只有在edittext
中有150个字符时才可见。
我试过像这样修理它:
@Override
public void afterTextChanged(Editable s) {
if(s.length() <= 149){
但这使得按钮&#34; flash
&#34;每次写一个角色。
关于我如何禁用该按钮的任何提示,然后仅在有150个字符时显示,然后在删除字符时再次禁用?
答案 0 :(得分:1)
检查字符长度greater than and equal to 150
并将其设为visible
其他hide
。
if(s.length() >= 150){
bubble.setVisibility(View.VISIBLE);
}
else{
bubble.setVisibility(View.GONE);
}