List of usage examples for android.widget TextView addTextChangedListener
public void addTextChangedListener(TextWatcher watcher)
From source file:io.github.rockerhieu.emojiconize.EmojiconLayoutInflaterFactory.java
@Override public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { View view = builder.activity.getDelegate().createView(parent, name, context, attrs); if (view instanceof EmojiconTextView || view instanceof EmojiconEditText || view instanceof EmojiconMultiAutoCompleteTextView) { return view; }// w w w . j a v a2 s . c om if (view == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); try { view = inflater.createView(name, null, attrs); } catch (Exception ignored) { } } if (view instanceof TextView) { TextView textView = (TextView) view; textView.addTextChangedListener(new EmojiconTextWatcher(textView, builder)); } return view; }
From source file:ch.dissem.apps.abit.SubscriptionDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_subscription_detail, container, false); // Show the dummy content as text in a TextView. if (item != null) { ((ImageView) rootView.findViewById(R.id.avatar)).setImageDrawable(new Identicon(item)); TextView name = (TextView) rootView.findViewById(R.id.name); name.setText(item.toString());/*from w w w. j ava 2s. com*/ name.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Nothing to do } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // Nothing to do } @Override public void afterTextChanged(Editable s) { item.setAlias(s.toString()); } }); TextView address = (TextView) rootView.findViewById(R.id.address); address.setText(item.getAddress()); address.setSelected(true); ((TextView) rootView.findViewById(R.id.stream_number)) .setText(getActivity().getString(R.string.stream_number, item.getStream())); Switch active = (Switch) rootView.findViewById(R.id.active); active.setChecked(item.isSubscribed()); active.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { item.setSubscribed(isChecked); } }); } return rootView; }
From source file:net.frakbot.FWeather.activity.LocationChooserDialog.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // This sets the window size, while working around the IllegalStateException thrown by ActionBarView getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); setContentView(R.layout.dialog_weather_location_chooser); TextView searchView = (TextView) findViewById(R.id.location_query); searchView.addTextChangedListener(this); // Set up apps mSearchResultsList = (ListView) findViewById(android.R.id.list); mSearchResultsList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from ww w.j a v a 2 s .c o m public void onItemClick(AdapterView<?> listView, View view, int position, long itemId) { String value = mSearchResultsAdapter.getPrefValueAt(position); FLog.d(TAG, "User has selected an item: " + value); try { sendBroadcast(new Intent(WeatherLocationPreference.ACTION_SET_VALUE) .putExtra(WeatherLocationPreference.EXTRA_VALUE, value).setPackage(getPackageName())); } catch (Exception e) { FLog.w(TAG, "Unable to send the SET_VALUE broadcast", e); } mSelectedValue = true; finish(); } }); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); tryBindList(); }
From source file:com.albertcbraun.cms50fw.alert.MainUIFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.v(TAG, "onCreateView"); View rootView = inflater.inflate(R.layout.fragment_main_activity, container, false); // UI elements messageWindow = (TextView) rootView.findViewById(R.id.message_window); messageWindowScrollView = (ScrollView) rootView.findViewById(R.id.message_window_scroll_view); timeWindow = (TextView) rootView.findViewById(R.id.current_time_window); spo2Window = (TextView) rootView.findViewById(R.id.current_spo2_window); pulseWindow = (TextView) rootView.findViewById(R.id.current_pulse_window); connectButton = (Button) rootView.findViewById(R.id.connect_button); Button startReadingDataButton = (Button) rootView.findViewById(R.id.start_reading_data_button); Button stopReadingDataButton = (Button) rootView.findViewById(R.id.stop_reading_data_button); TextView minimumSpo2PercentageText = (TextView) rootView.findViewById(R.id.minimum_spo2_percentage_text); minimumSpo2PercentageText.addTextChangedListener(new Spo2PercentageTextChangedListener(this)); SeekBar minimumSpo2PercentageSeekBar = (SeekBar) rootView.findViewById(R.id.minimum_spo2_percentage); setUpSeekBar(PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()), minimumSpo2PercentageSeekBar, minimumSpo2PercentageText, minimumSpo2Percentage, MAXIMUM_SPO2_PERCENTAGE_MAX_VALUE_KEY_NAME, MAXIMUM_SPO2_PERCENTAGE_DEFAULT_VALUE, CURRENT_SPO2_PERCENTAGE_MAX_VALUE_KEY_NAME, CURRENT_SPO2_PERCENTAGE_DEFAULT_VALUE); connectButton.setEnabled(true);//from w w w .j av a 2 s. c o m startReadingDataButton.setEnabled(false); stopReadingDataButton.setEnabled(false); soundPool = new SoundPool(MAX_STREAMS, AudioManager.STREAM_ALARM, SRC_QUALITY); // set a custom callback which is fully aware of the main fragment's UI CMS50FWConnectionListener cms50fwCallbacks = new CMS50FWCallbacks(this, connectButton, startReadingDataButton, stopReadingDataButton); this.cms50FWBluetoothConnectionManager.setCMS50FWConnectionListener(cms50fwCallbacks); return rootView; }
From source file:com.ushahidi.android.app.ui.tablet.ListCheckinFragment.java
protected View headerView() { LayoutInflater inflater = getActivity().getLayoutInflater(); ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.list_checkin_header, getListView(), false); TextView textView = (TextView) viewGroup.findViewById(R.id.filter_checkins); textView.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable arg0) { }/* www.ja v a2s. c om*/ public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { if (!(TextUtils.isEmpty(s.toString()))) { filterTitle = s; mHandler.post(filterCheckinList); } else { mHandler.post(fetchCheckinList); } } }); return viewGroup; }
From source file:org.sharetomail.AddModifyEmailAddressActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Util.uncaughtExceptionHandling(); setContentView(R.layout.activity_add_email_address); // Show the Up button in the action bar. setupActionBar();//from www. j a va2s . c o m config = new Configuration(getSharedPreferences(Constants.SHARED_PREFERENCES_NAME, MODE_PRIVATE)); final Button addModifyEmailAddressButton = (Button) findViewById(R.id.addModifyEmailAddressButton); final TextView emailAddressTextView = (TextView) findViewById(R.id.emailAddressEditText); emailAppButton = (Button) findViewById(R.id.emailAppButton); // Custom text change listener to enable/disable the add/modify email // address button when the input text changes. emailAddressTextView.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.length() > 0) { addModifyEmailAddressButton.setEnabled(true); } else { addModifyEmailAddressButton.setEnabled(false); } } }); addModifyEmailAddressButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Check if the input is in email address format. If it is not // warn the user. String inputText = emailAddressTextView.getText().toString().trim(); if (Util.isInEmailFormat(inputText)) { EmailAddress emailAddress = new EmailAddress(inputText, emailAppName, emailAppPackageName); if (origEmail != null) { int position = -1; for (int i = 0; i < config.getEmailAddresses().size(); i++) { if (origEmail.equals(config.getEmailAddresses().get(i))) { position = i; break; } } // Original email address was not found (somebody // removed it in the mean time?) so we add it. if (position < 0) { Log.w(TAG, "Email address \"" + origEmail.getEmailAddress() + "\" was not found which is bad. Adding it."); config.addEmailAddress(emailAddress); } else { config.setEmailAddress(position, emailAddress); } } else { config.addEmailAddress(emailAddress); } setResult(Activity.RESULT_OK, getIntent()); finish(); } else { Toast.makeText(AddModifyEmailAddressActivity.this, getString(R.string.dialog_input_is_not_in_email_format), Toast.LENGTH_LONG).show(); } } }); emailAppButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startEmailAppSelector(); } }); // If we get the email address in the intent then we modify it so fill // the TextView and rename labels. if (getIntent().hasExtra(Constants.ORIG_EMAIL_ADDRESS_INTENT_KEY)) { origEmail = getIntent().getParcelableExtra(Constants.ORIG_EMAIL_ADDRESS_INTENT_KEY); emailAppName = origEmail.getEmailAppName(); emailAppPackageName = origEmail.getEmailAppPackageName(); setTitle(R.string.title_activity_modify_email_address); addModifyEmailAddressButton.setText(R.string.modify_email_address_button); emailAddressTextView.setText(origEmail.getEmailAddress()); setEmailAppButtonText(); } }
From source file:com.kunze.androidlocaltodo.TaskActivityFragment.java
private void InitializeView(final View rootView) { final View activityView = rootView; TextWatcher textWatcher = new TextWatcher() { @Override//w ww .j av a2s. c om public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { TaskChanged(activityView); } }; final EditText nameEdit = (EditText) rootView.findViewById(R.id.task_name_edit); final TextView nameStatic = (TextView) rootView.findViewById(R.id.task_name_static); nameStatic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { nameEdit.setVisibility(View.VISIBLE); nameStatic.setVisibility(View.INVISIBLE); } }); nameEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { nameEdit.setVisibility(View.INVISIBLE); nameStatic.setVisibility(View.VISIBLE); } } }); nameEdit.addTextChangedListener(textWatcher); final TextView descriptionEdit = (TextView) rootView.findViewById(R.id.task_description_edit); descriptionEdit.addTextChangedListener(textWatcher); final TextView dueDateView = (TextView) rootView.findViewById(R.id.due_date_text); final DatePicker datePicker = (DatePicker) rootView.findViewById(R.id.due_date_calendar); datePicker.init(0, 0, 0, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(year, monthOfYear, dayOfMonth, 0, 0, 0); SetFriendlyDueDateText(dueDateView, calendar); TaskChanged(activityView); } }); Button todayButton = (Button) rootView.findViewById(R.id.today_button); todayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar now = Calendar.getInstance(); datePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, now); } }); Button plusDayButton = (Button) rootView.findViewById(R.id.plus_day_button); plusDayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); calendar.add(Calendar.DATE, 1); datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, calendar); } }); Button thisWeekendButton = (Button) rootView.findViewById(R.id.this_weekend_button); thisWeekendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar weekend = Calendar.getInstance(); while (weekend.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) { weekend.add(Calendar.DATE, 1); } datePicker.updateDate(weekend.get(Calendar.YEAR), weekend.get(Calendar.MONTH), weekend.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, weekend); } }); Button plusWeekButton = (Button) rootView.findViewById(R.id.plus_week_button); plusWeekButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); calendar.add(Calendar.DATE, 7); datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, calendar); } }); final CheckBox repeatCheck = (CheckBox) rootView.findViewById(R.id.repeat); repeatCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { View dialog = (View) buttonView.getParent(); SetRepeatVisibility(dialog, isChecked); TaskChanged(activityView); } }); final EditText repeatTimeEdit = (EditText) rootView.findViewById(R.id.repeat_time); repeatTimeEdit.addTextChangedListener(textWatcher); final Spinner repeatUnitSpinner = (Spinner) rootView.findViewById(R.id.repeat_unit); String[] repeatUnits = { "Days", "Weeks", "Months", "Years" }; repeatUnitSpinner.setAdapter( new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, repeatUnits)); repeatUnitSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (mRow != -1 && mRow != id) { TaskChanged(activityView); } mRow = id; } @Override public void onNothingSelected(AdapterView<?> arg0) { TaskChanged(activityView); } private long mRow = -1; }); final RadioButton repeatFromComplete = (RadioButton) rootView.findViewById(R.id.repeat_from_complete); final RadioButton repeatFromDue = (RadioButton) rootView.findViewById(R.id.repeat_from_due); Button revertButton = (Button) rootView.findViewById(R.id.revert_button); Button acceptButton = (Button) rootView.findViewById(R.id.accept_button); final Button doneButton = (Button) rootView.findViewById(R.id.done_button); Button deleteButton = (Button) rootView.findViewById(R.id.delete_button); revertButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mNewTask = new Task(mOriginalTask); mProgrammaticChange = true; InitializeViewFields(activityView, mOriginalTask); mProgrammaticChange = false; TaskReverted(activityView); } }); doneButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(doneButton.getContext()); builder.setTitle("Done?"); builder.setMessage("Mark task \"" + mNewTask.mName + "\" as done?"); builder.setNegativeButton("No", null); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mNewTask.Done(); TaskDatabase db = new TaskDatabase(getActivity()); db.SaveTask(mNewTask); InitializeViewFields(rootView, mNewTask); } }); builder.show(); } }); }
From source file:org.rm3l.ddwrt.tiles.status.wan.WANMonthlyTrafficTile.java
public WANMonthlyTrafficTile(@NotNull SherlockFragment parentFragment, @NotNull Bundle arguments, Router router) {//from w w w .j av a 2 s . co m super(parentFragment, arguments, router, R.layout.tile_status_wan_monthly_traffic, R.id.tile_status_wan_monthly_traffic_togglebutton); final TextView monthYearTextViewToDisplay = (TextView) this.layout .findViewById(R.id.tile_status_wan_monthly_month_displayed); monthYearTextViewToDisplay.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) { final String toDisplay = monthYearTextViewToDisplay.getText().toString(); final boolean isCurrentMonthYear = SIMPLE_DATE_FORMAT.format(new Date()).equals(toDisplay); WANMonthlyTrafficTile.this.layout .findViewById(R.id.tile_status_wan_monthly_traffic_graph_placeholder_current) .setEnabled(!isCurrentMonthYear); WANMonthlyTrafficTile.this.layout .findViewById(R.id.tile_status_wan_monthly_traffic_graph_placeholder_next) .setEnabled(!isCurrentMonthYear); WANMonthlyTrafficTile.this.layout .findViewById(R.id.tile_status_wan_monthly_traffic_graph_placeholder_display_button) .setVisibility(isNullOrEmpty(toDisplay) ? View.GONE : View.VISIBLE); } }); }
From source file:com.ushahidi.android.app.ui.tablet.ListReportFragment.java
protected View headerView() { LayoutInflater inflater = getActivity().getLayoutInflater(); ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.list_report_header, getListView(), false); TextView textView = (TextView) viewGroup.findViewById(R.id.filter_report); textView.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable arg0) { }// w w w.j a v a 2 s . c om public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { if (!(TextUtils.isEmpty(s.toString()))) { filterTitle = s; mHandler.post(filterReportList); } } }); return viewGroup; }
From source file:Main.java
/** * Make a textview to a collapsible textview with the indicator on the right of the textview * /* w ww. j a v a 2s. c om*/ * @param tv , {@link TextView} to be converted * @param upDrawableResId , drawable resource id to be used as up indicator * @param downDrawableResId , drawable resource id to be used as down indicator * @param lineTreshold , no of line to be displayed for the collapsed state */ public static void makeCollapsible(final TextView tv, int upDrawableResId, int downDrawableResId, final int lineTreshold) { final Drawable[] drawables = tv.getCompoundDrawables(); final Drawable up = tv.getContext().getResources().getDrawable(upDrawableResId); final Drawable down = tv.getContext().getResources().getDrawable(downDrawableResId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); tv.setEllipsize(TruncateAt.END); tv.setMaxLines(lineTreshold); tv.setTag(true); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v instanceof TextView) { TextView tv = (TextView) v; boolean snippet = (Boolean) tv.getTag(); if (snippet) { // show everything snippet = false; tv.setMaxLines(Integer.MAX_VALUE); tv.setEllipsize(null); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], up, drawables[3]); } else { // show snippet snippet = true; tv.setMaxLines(lineTreshold); tv.setEllipsize(TruncateAt.END); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); } tv.setTag(snippet); } } }); } else { tv.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { ViewTreeObserver vto = tv.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @SuppressLint("NewApi") @Override public void onGlobalLayout() { tv.setEllipsize(TruncateAt.END); int line = tv.getLineCount(); tv.setMaxLines(lineTreshold); if (line <= lineTreshold) { tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // empty listener // Log.d("line count", "count: "+ // tv.getLineCount()); } }); if (tv.getLayout() != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { tv.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { tv.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } return; } tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); tv.setTag(true); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v instanceof TextView) { TextView tv = (TextView) v; boolean snippet = (Boolean) tv.getTag(); if (snippet) { snippet = false; // show everything tv.setMaxLines(Integer.MAX_VALUE); tv.setEllipsize(null); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], up, drawables[3]); } else { snippet = true; // show snippet tv.setMaxLines(lineTreshold); tv.setEllipsize(TruncateAt.END); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); } tv.setTag(snippet); } } }); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { tv.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { tv.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } }); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); } }