private class TextChangeWatcher implements TextWatcher { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String username = mUserNameET.getText().toString().trim(); if (TextUtils.isEmpty(username)) { return; } Map<String, String> map = new HashMap<String, String>(); map.put("nickname", username); VolleyRequest.RequestPost(MyApplication.getContext(), Allurl.queryFriends, "getUserData", map, new VolleyInterface(MyApplication.getContext(), VolleyInterface.mlistener, VolleyInterface.merrorlistener) { @Override public void onMySuccess(String response) { MyLog.i("test26", "respnse = " + response); if (!response.equals("error")) { MyLog.i("test26", "response = " + response); } else { Toast.makeText(LoginActivity.this, "服务器返回错误!", Toast.LENGTH_SHORT).show(); } } @Override public void onMyError(VolleyError error) { Toast.makeText(LoginActivity.this, "网络异常!", Toast.LENGTH_SHORT).show(); } });}
用法:
Etidtext.addTextChangedListener(new TextChangeWatcher());
EditText动态输入监听
最新推荐文章于 2025-07-17 13:21:41 发布
本文介绍了一种在Android应用中实现文本变化监听的方法。通过自定义TextWatcher类,当输入框内的文本发生变化时,可以实时获取到最新的文本内容,并根据内容进行相应的网络请求操作。示例代码展示了如何设置及使用该监听器。

1633

被折叠的 条评论
为什么被折叠?



