首页 > 代码库 > TextWatcher() 的用法
TextWatcher() 的用法
实例一:
phone_view.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {Log.i(TAG, "onTextChanged =" + s + " start:" + start + " before:" + before + " count " + count);
if(application.contactPersionList ==null || application.contactPersionList.size()==0 || "".equals(s.toString())){
listView.setVisibility(View.INVISIBLE);
callLogList.setVisibility(View.VISIBLE);
}else{
if(null == t9Adapter){
t9Adapter = new T9Adapter(HomeDialActivity.this);
contactList.addAll(application.contactPersionList);
t9Adapter.assignment(contactList);
listView.setAdapter(t9Adapter);
listView.setTextFilterEnabled(true);
listView.setOnScrollListener(new OnScrollListener() {
public void onScrollStateChanged(AbsListView view, int scrollState) {
if(scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){
if(bohaopan.getVisibility() == View.VISIBLE){
bohaopan.setVisibility(View.GONE);
}
}
}
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
}
});
}
t9Adapter.getFilter().filter(s);
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Log.i(TAG, "beforeTextChanged =" + s + " start:" + start + " after:" + after + " count " + count);
}
public void afterTextChanged(Editable s) {
Log.i(TAG, "afterTextChanged = " + s.toString());
String phone = s.toString();
//对长度进行判断;
if(!TextUtils.isEmpty(phone) && phone.length() >= 10 && phone.length() <= 15){
if(!Utils.isMcwillNumber(phone) && AppUtils.isSipConnected(HomeDialActivity.this)){//非M网,则进行远端查询
new AsySearchOnLineTask(phone).execute();
}
}
}
});
实例二:
etSearch = (EditText)findViewById(R.id.etSearch);
etSearch.addTextChangedListener(searchWatcher);
TextWatcher searchWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
if(chatHistoryAdapter != null){
chatHistoryAdapter.getFilter().filter(arg0);
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
};
实例三:
editText1 = (EditText) findViewById(R.id.lin_search_edit);
editText1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable edit) {
if (adapter != null) {
adapter.getFilter().filter(edit);
}
}
@Override
public void beforeTextChanged(CharSequence charsequence, int i,int j, int k) {
}
@Override
public void onTextChanged(CharSequence charsequence, int i, int j,int k) {
}
});
实例四:
// 搜索的监听
edit_input.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(adapter!=null)
{
adapter.getFilter().filter(s);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
};
});
实例五:
editText1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable edit) {
if (adapter != null && isNeedFilter) {
adapter.getFilter().filter(edit);// Adapter类中实现Filterable方法,并且重写getFilter()
}
}
@Override
public void beforeTextChanged(CharSequence charsequence, int i,
int j, int k) {
}
@Override
public void onTextChanged(CharSequence charsequence, int i, int j,
int k) {
}
});
实例六:
meetingReplyMsg.addTextChangedListener(textWatcher);
/**
* TextWatcher
*/
TextWatcher textWatcher = new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
System.out.println("---s.toString()---:" + s.toString());
if (!Utils.isStrEmpty(s.toString())) {
Config._reply_msg.set(s.toString().trim());
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
};
实例七:
mEdPhone.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.toString().length() > 0) {
mBtnRegister.setClickable(true);
mBtnRegister.setBackgroundResource(R.drawable.loginbtn);
} else if (s.toString().length() == 0) {
mBtnRegister.setClickable(false);
mBtnRegister
.setBackgroundResource(R.drawable.button_no_cliable);
}
mPhoneNumber = mEdPhone.getText().toString().trim();
}
});
实例八:
editText1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable edit) {
if (adapter != null) {
adapter.getFilter().filter(edit);
}
}
@Override
public void beforeTextChanged(CharSequence charsequence, int i,
int j, int k) {
}
@Override
public void onTextChanged(CharSequence charsequence, int i, int j,
int k) {
}
});
实例九:
// 获取编辑框焦点
editText.setFocusable(true);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
editText.setSelection(s.length());
Log.v("CustomDialog", "666666"+s.length());
}
});
实例十:
searchBox = (EditText) view.findViewById(R.id.com_facebook_picker_search_text);
searchBox.addTextChangedListener(new SearchTextWatcher());
if (!TextUtils.isEmpty(searchText)) {
searchBox.setText(searchText);
}
private class SearchTextWatcher implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
onSearchBoxTextChanged(s.toString(), false);
}
@Override
public void afterTextChanged(Editable s) {
}
}
TextWatcher() 的用法