use of android.text.TextWatcher in project Android-Developers-Samples by johnjohndoe.
the class LogFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View result = inflateViews();
mLogView.addTextChangedListener(new 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) {
}
@Override
public void afterTextChanged(Editable s) {
mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});
return result;
}
use of android.text.TextWatcher in project EditTextInListView by Aspsine.
the class LineAdapter method getView.
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_line, parent, false);
holder.etLine = (EditText) convertView.findViewById(R.id.etLine);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final Line line = lines.get(position);
if (holder.etLine.getTag() instanceof TextWatcher) {
holder.etLine.removeTextChangedListener((TextWatcher) (holder.etLine.getTag()));
}
holder.etLine.setHint(position + ".");
if (TextUtils.isEmpty(line.getText())) {
holder.etLine.setText("");
} else {
holder.etLine.setText(line.getText());
}
if (line.isFocus()) {
if (!holder.etLine.isFocused()) {
holder.etLine.requestFocus();
}
CharSequence text = line.getText();
holder.etLine.setSelection(TextUtils.isEmpty(text) ? 0 : text.length());
} else {
if (holder.etLine.isFocused()) {
holder.etLine.clearFocus();
}
}
holder.etLine.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(final View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
final boolean focus = line.isFocus();
check(position);
if (!focus && !holder.etLine.isFocused()) {
holder.etLine.requestFocus();
holder.etLine.onWindowFocusChanged(true);
}
}
return false;
}
});
final TextWatcher watcher = new SimpeTextWather() {
@Override
public void afterTextChanged(Editable s) {
if (TextUtils.isEmpty(s)) {
line.setText(null);
} else {
line.setText(String.valueOf(s));
}
}
};
holder.etLine.addTextChangedListener(watcher);
holder.etLine.setTag(watcher);
return convertView;
}
use of android.text.TextWatcher in project AndroidChromium by JackyAndroid.
the class NewTabPageView method initializeSearchBoxTextView.
/**
* Sets up the hint text and event handlers for the search box text view.
*/
private void initializeSearchBoxTextView() {
final TextView searchBoxTextView = (TextView) mSearchBoxView.findViewById(R.id.search_box_text);
String hintText = getResources().getString(R.string.search_or_type_url);
if (!DeviceFormFactor.isTablet(getContext()) || mManager.isFakeOmniboxTextEnabledTablet()) {
searchBoxTextView.setHint(hintText);
} else {
searchBoxTextView.setContentDescription(hintText);
}
searchBoxTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mManager.focusSearchBox(false, null);
}
});
searchBoxTextView.addTextChangedListener(new 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) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() == 0)
return;
mManager.focusSearchBox(false, s.toString());
searchBoxTextView.setText("");
}
});
}
use of android.text.TextWatcher in project AndroidChromium by JackyAndroid.
the class FloatLabelLayout method setEditText.
private void setEditText(EditText editText) {
// If we already have an EditText, throw an exception
if (mEditText != null) {
throw new IllegalArgumentException("We already have an EditText, can only have one");
}
mEditText = editText;
// Update the label visibility with no animation
updateLabelVisibility(false);
// Add a TextWatcher so that we know when the text input has changed
mEditText.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
updateLabelVisibility(true);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
// Add focus listener to the EditText so that we can notify the label that it is activated.
// Allows the use of a ColorStateList for the text color on the label
mEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean focused) {
updateLabelVisibility(true);
}
});
// If we do not have a valid hint, try and retrieve it from the EditText
if (TextUtils.isEmpty(mHint)) {
setHint(mEditText.getHint());
}
// If we do not have a valid content description, set it to the hint text.
if (TextUtils.isEmpty(mEditText.getContentDescription())) {
mEditText.setContentDescription(mHint);
}
}
use of android.text.TextWatcher in project UltimateAndroid by cymcsg.
the class MarqueeView method initView.
private void initView(Context context) {
// Scroll View
LayoutParams sv1lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
sv1lp.gravity = Gravity.CENTER_HORIZONTAL;
mScrollView = new ScrollView(context);
// Scroll View 1 - Text Field
mTextField = (TextView) getChildAt(0);
removeView(mTextField);
mScrollView.addView(mTextField, new ScrollView.LayoutParams(TEXTVIEW_VIRTUAL_WIDTH, LayoutParams.WRAP_CONTENT));
mTextField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
final boolean continueAnimation = mStarted;
reset();
prepareAnimation();
cutTextView();
post(new Runnable() {
@Override
public void run() {
if (continueAnimation) {
startMarquee();
}
}
});
}
});
addView(mScrollView, sv1lp);
}
Aggregations