本文整理汇总了Java中android.text.TextWatcher类的典型用法代码示例。如果您正苦于以下问题:Java TextWatcher类的具体用法?Java TextWatcher怎么用?Java TextWatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextWatcher类属于android.text包,在下文中一共展示了TextWatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beautyEditText
import android.text.TextWatcher; //导入依赖的package包/类
protected void beautyEditText(final EditText mEditText, String hintStr, TextWatcher mTextWatcher) {
mEditText.setHint(hintStr);
mEditText.setHintTextColor(Color.parseColor("#1e0d0d0d"));
mEditText.setTextColor(Color.parseColor("#0d0d0d"));
SDKUtils.setBackground(mEditText, this.crMgmt.getDrawable("uac_input", true));
mEditText.setTextSize(16.0f);
if (mTextWatcher != null) {
mEditText.addTextChangedListener(mTextWatcher);
}
mEditText.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mEditText.setSelection(mEditText.length());
mEditText.requestFocus();
mEditText.setFocusable(true);
}
});
}
示例2: initListener
import android.text.TextWatcher; //导入依赖的package包/类
private void initListener() {
findViewById(R.id.constraint_layout).setOnClickListener(this);
fab.setOnClickListener(this);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
needClearInput = false;
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
textInputLayout.setErrorEnabled(false);
}
@Override
public void afterTextChanged(Editable editable) {
editTextString = editText.getText().toString();
if (editTextString.equals(""))
setFabImage(false);
}
});
}
示例3: removeTextChangedListener
import android.text.TextWatcher; //导入依赖的package包/类
@Override
public void removeTextChangedListener(TextWatcher watcher) {
super.removeTextChangedListener(watcher);
if (mCsDrawableViewManager != null){
mCsDrawableViewManager.removeTextWatcher();
}
}
示例4: doNotAddTextWatcher_IfAlreadyAdded
import android.text.TextWatcher; //导入依赖的package包/类
@Test
public void doNotAddTextWatcher_IfAlreadyAdded() throws Exception {
// Given
given(view.getTag(anyInt()))
.willReturn(mock(TextWatcher.class));
BindingFunction function = TextChangedBindingFunction.create(listener);
// When
function.bind(view);
// Then
verify(view, never()).addTextChangedListener(any());
}
示例5: removeTextWatcher
import android.text.TextWatcher; //导入依赖的package包/类
@Test
public void removeTextWatcher() throws Exception {
// Given
TextWatcher watcher = mock(TextWatcher.class);
given(view.getTag(anyInt()))
.willReturn(watcher);
BindingFunction function = TextChangedBindingFunction.create(null);
// When
function.bind(view);
// Then
verify(view).removeTextChangedListener(watcher);
verify(view).setTag(R.id.onTextChangedListener, null);
}
示例6: buildForm
import android.text.TextWatcher; //导入依赖的package包/类
private void buildForm() {
EditText formMessage = findViewById(R.id.form_input_message);
AutoCompleteTextView formContact = findViewById(R.id.form_input_contact);
TextWatcher watcherEmptiness = new EmptinessTextWatcher(this, formContact, formMessage);
formContact.addTextChangedListener(watcherEmptiness);
formMessage.addTextChangedListener(watcherEmptiness);
new BuilderMessage().setView(formMessage).setSms(sms).build();
new BuilderContact().setView(formContact).setSms(sms).setActivity(this).build();
new BuilderSimCard().setActivity(this).setView(findViewById(R.id.form_sim_card)).setSms(sms).build();
new BuilderRecurringMode()
.setRecurringDayView((Spinner) findViewById(R.id.form_recurring_day))
.setRecurringMonthView((Spinner) findViewById(R.id.form_recurring_month))
.setDateView((DatePicker) findViewById(R.id.form_date))
.setActivity(this)
.setView(findViewById(R.id.form_recurring_mode))
.setSms(sms)
.build()
;
new BuilderTime().setActivity(this).setView(findViewById(R.id.form_time)).setSms(sms).build();
new BuilderDate().setActivity(this).setView(findViewById(R.id.form_date)).setSms(sms).build();
new BuilderCancel().setView(findViewById(R.id.button_cancel)).setSms(sms).build();
}
示例7: createSelectStringDialogFilterTextWatcher
import android.text.TextWatcher; //导入依赖的package包/类
private static TextWatcher createSelectStringDialogFilterTextWatcher(final Activity activity
, final List<Pair<Bitmap, String>> values
, final double maxImageWidthInCM
, final double maxImageHeightInCM
, EditText filterText
, final boolean matchCase
, final boolean containsMode
, final boolean multiSelect
, final ListView list
, final SortedSet<String> allSelectedItems
, final ReturnableObject<FLUIAndroidIconLabelAndCheckListAdapter>
currentCheckListAdapter) {
return createSelectStringDialogFilterTextWatcher(activity
, values
, maxImageWidthInCM
, maxImageHeightInCM
, DEFAULT_TEXT_SIZE_IN_DIP
, SizeUnit.DIP
, filterText
, matchCase
, containsMode
, multiSelect
, list
, allSelectedItems
, currentCheckListAdapter);
}
示例8: testInputEmail
import android.text.TextWatcher; //导入依赖的package包/类
@Test
public void testInputEmail() {
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append("abcdef");
TextWatcher textWatcher = new CustomTextWatcher() {
@Override
public void afterTextChanged(Editable editable) {
super.afterTextChanged(editable);
loginRequest.setEmail(editable.toString());
}
};
assertEquals("abcdef", builder.toString());
textWatcher.afterTextChanged(builder);
assertFalse(loginRequest.isEmailEmpty());
assertFalse(loginRequest.isValidEmail());
builder.clear();
builder.append("[email protected]");
textWatcher.afterTextChanged(builder);
assertTrue(loginRequest.isValidEmail());
}
示例9: testInputPassword
import android.text.TextWatcher; //导入依赖的package包/类
@Test
public void testInputPassword() {
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append("abcd");
TextWatcher textWatcher = new CustomTextWatcher() {
@Override
public void afterTextChanged(Editable editable) {
super.afterTextChanged(editable);
loginRequest.setPassword(editable.toString());
}
};
textWatcher.afterTextChanged(builder);
assertFalse(loginRequest.isPasswordEmpty());
assertFalse(loginRequest.isValidPassword());
builder.clear();
builder.append("abcd123");
textWatcher.afterTextChanged(builder);
assertTrue(loginRequest.isValidPassword());
}
示例10: onFocusChange
import android.text.TextWatcher; //导入依赖的package包/类
@Override
public void onFocusChange(View v, boolean has_focus)
{
EditText ed = (EditText)v;
TextWatcher w = (TextWatcher)ed.getTag();
ed.removeTextChangedListener(w);
if(has_focus)
{
ed.setSelection(ed.getText().length());
if(focus_listener != null)
{
focus_listener.FocusReceived(tag);
}
}
ed.addTextChangedListener(w);
}
示例11: setValue
import android.text.TextWatcher; //导入依赖的package包/类
public void setValue(BigDecimal value)
{
TextWatcher w = (TextWatcher)editor.getTag();
editor.removeTextChangedListener(w);
if(value.compareTo(min) < 0)
{
value = min;
}
if(value.compareTo(max) > 0)
{
value = max;
}
DecimalFormat formatter = new DecimalFormat("###.##");
editor.setText(formatter.format(value));
editor.addTextChangedListener(w);
}
示例12: onFocusChange
import android.text.TextWatcher; //导入依赖的package包/类
@Override
public void onFocusChange(View v, boolean has_focus)
{
EditText ed = (EditText)v;
TextWatcher w = (TextWatcher)ed.getTag();
ed.removeTextChangedListener(w);
if(has_focus)
{
ed.setSelection(ed.getText().length());
} else
{
int i = getValue(ed.getText().toString());
ed.setText(String.valueOf(i));
}
ed.addTextChangedListener(w);
}
示例13: onFocusChange
import android.text.TextWatcher; //导入依赖的package包/类
@Override
public void onFocusChange(View v, boolean has_focus)
{
EditText ed = (EditText)v;
TextWatcher w = (TextWatcher)ed.getTag();
ed.removeTextChangedListener(w);
if(has_focus)
{
ed.setSelection(ed.getText().length());
if(focus_listener != null)
{
focus_listener.FocusReceived(tag);
}
}/* else
{
double i = get(ed.getText().toString());
ed.setText(String.valueOf(i));
}*/
ed.addTextChangedListener(w);
}
示例14: checkIsCorrectTextWatcher
import android.text.TextWatcher; //导入依赖的package包/类
protected boolean checkIsCorrectTextWatcher(Editable editable, TextWatcher textWatcher) {
CARD_TYPE currentCardType = getCurrentCardType();
CARD_TYPE newCardType = getNewCardType(editable.toString());
if(newCardType == currentCardType) {
return true;
}
if(newCardType == CARD_TYPE.OTHERS) {
mEditText.removeTextChangedListener(textWatcher);
mEditText.addTextChangedListener(new OtherCardTextWatcher(mEditText));
mEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(OTHERS_MAX_LENGTH)});
setCursorPosition();
} else if(newCardType == CARD_TYPE.AMERICAN_EXPRESS) {
mEditText.removeTextChangedListener(textWatcher);
mEditText.addTextChangedListener(new AmericanExpressTextWatcher(mEditText));
mEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(AMERICAN_EXPRESS_MAX_LENGTH)});
setCursorPosition();
}
return false;
}
示例15: searchableListAlert
import android.text.TextWatcher; //导入依赖的package包/类
public <T> AlertDialog.Builder searchableListAlert(final TextView text, final TextView title, final ArrayAdapter<T> adapter,
final ArrayList<T> list, final OnItemClickListener listener, TextWatcher textWatcher) {
LayoutInflater factory = LayoutInflater.from(context);
final LinearLayout alertView = (LinearLayout) factory.inflate(R.layout.alert_view_searchable_list, null);
final EditText editText = (EditText) alertView.findViewById(R.id.edit_text);
final ListView listView = (ListView) alertView.findViewById(R.id.list);
listView.setOnItemClickListener(listener);
listView.setAdapter(adapter);
// Search text watcher.
editText.addTextChangedListener(textWatcher);
textWatcher.onTextChanged("", 0, 0, 0);
return new AlertDialog.Builder(context)
.setTitle(title.getText().toString())
.setView(alertView)
.setNegativeButton(R.string.cancel, null);
}