android中edittext怎么监听字体长度
1个回答
2015-03-21 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517199
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
这个监听就是addTextChangedListener(EditText s).
public class EditTextActivity extends Activity implements OnClickListener{
private EditText adb_password;
public boolean change = false;
private LinearLayout adb_lin2;
private Button button1;
private Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kvadb);
adb_password = (EditText) findViewById(R.id.adb_password);
adb_lin2 = (LinearLayout) findViewById(R.id.adb_lin2);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
adb_password.addTextChangedListener(mEditText);
}
TextWatcher mEditText = new TextWatcher() {
private CharSequence temp;
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
temp = s;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
adb_password.setVisibility(View.VISIBLE);
adb_lin2.setVisibility(View.GONE);
}
@Override
public void afterTextChanged(Editable s) {
if(adb_password.getText().length() == 6){
if(adb_password.getText().toString().equals("111111")){
adb_password.setVisibility(View.GONE);
adb_password.setFocusableInTouchMode(false);
adb_password.setFocusable(false);
adb_lin2.setVisibility(View.VISIBLE);
adb_lin2.setFocusableInTouchMode(true);
button1.requestFocus();
}
}
}
};
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
Toast.makeText(KvAdb.this, "llll", 0).show();
break;
case R.id.button2:
finish();
break;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询