List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:com.michael.feng.textlater.NewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Remove title bar // requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_new); getSupportActionBar().setDisplayUseLogoEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setDisplayShowHomeEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(R.layout.abs_layout_new); backButton = (ImageView) findViewById(R.id.back); backButton.setOnClickListener(new OnClickListener() { @Override/*from w w w .j av a 2s. c o m*/ public void onClick(View arg0) { finish(); } }); backButton.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // touch down code backButton.setBackgroundColor(Color.rgb(104, 156, 210)); break; case MotionEvent.ACTION_MOVE: // touch move code break; case MotionEvent.ACTION_UP: // touch up code backButton.setBackgroundColor(Color.TRANSPARENT); break; } return false; } }); // Init Add Contact Button and EditText textContact = (EditText) findViewById(R.id.textContact); textContact.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { validateMessage(); } }); textContact.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { textContact.setSelection(textContact.getText().length()); } }); addContactButton = (Button) findViewById(R.id.addContactButton); addContactButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub Log.d("add button click", "hep"); Intent in = new Intent(getApplicationContext(), ContactsActivity.class); contactNames = textContact.getText().toString(); if (null != contactNames && !"".equals(contactNames)) { in.putExtra("contactNames", contactNames); in.putExtra("contactNumbers", contactNumbers); Log.d("addbutton contactNames", contactNames); Log.d("addbutton contactNumbers", contactNumbers); } int requestCode = 0; startActivityForResult(in, requestCode); } }); // Init TextDate EditText textDate = (EditText) findViewById(R.id.textDate); textDate.setInputType(InputType.TYPE_NULL); textDate.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (hasFocus) { showDatePickerDialog(view); } } }); textDate.setOnClickListener(this); // Init TextDate Button setDateButton = (Button) findViewById(R.id.setDateButton); setDateButton.setOnClickListener(this); // Init TextTime EditText textTime = (EditText) findViewById(R.id.textTime); textTime.setInputType(InputType.TYPE_NULL); textTime.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (hasFocus) { showTimePickerDialog(view); } } }); textTime.setOnClickListener(this); // Init TextTime Button setTimeButton = (Button) findViewById(R.id.setTimeButton); setTimeButton.setOnClickListener(this); // Init Active Button and Content EditText textContent = (EditText) findViewById(R.id.textContent); textContent.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { validateMessage(); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO } }); sendButton = (Button) findViewById(R.id.sendButton); sendButton.setOnClickListener(this); }
From source file:com.umeng.message.example.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); pushDao = PushDao.getInstance(this); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); screenWidth = dm.widthPixels;// ww w . j a v a2s. c om setContentView(R.layout.activity_main); printKeyValue(); mPushAgent = PushAgent.getInstance(this); mPushAgent.onAppStart(); mPushAgent.enable(MyApplication.mRegisterCallback); tvStatus = (TextView) findViewById(R.id.tvStatus); btnEnable = (ImageView) findViewById(R.id.btnEnable); btnaAddTag = (Button) findViewById(R.id.btnAddTags); btnAddAlias = (Button) findViewById(R.id.btnAddAlias); btnListTag = (Button) findViewById(R.id.btnListTags); infoTextView = (TextView) findViewById(R.id.info); edTag = (EditText) findViewById(R.id.edTag); edAlias = (EditText) findViewById(R.id.edAlias); edAliasType = (EditText) findViewById(R.id.edAliasType); spAliasType = (Spinner) findViewById(R.id.spAliasType); edAliasType.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { edAliasTypeFocus = true; } else { edAliasTypeFocus = false; } } }); edAliasType.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub if (edAliasTypeFocus) { spAliasType.setSelection(0); } } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); String[] aliasType = new String[] { "Alias Type:", ALIAS_TYPE.SINA_WEIBO, ALIAS_TYPE.BAIDU, ALIAS_TYPE.KAIXIN, ALIAS_TYPE.QQ, ALIAS_TYPE.RENREN, ALIAS_TYPE.TENCENT_WEIBO, ALIAS_TYPE.WEIXIN }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, aliasType); spAliasType.setAdapter(adapter); spAliasType.setBackgroundColor(Color.LTGRAY); spAliasType.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub TextView tv = (TextView) arg1; if (tv != null) { int rate = (int) (5.0f * (float) screenWidth / 320.0f); int textSize = rate < 15 ? 15 : rate; tv.setTextSize((float) textSize); } if (arg2 != 0) { String type = (String) spAliasType.getItemAtPosition(arg2); edAliasType.setText(type); } else if (!edAliasTypeFocus) { edAliasType.setText(""); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); tvStatus.setOnClickListener(clickListener); btnEnable.setOnClickListener(clickListener); btnaAddTag.setOnClickListener(clickListener); btnListTag.setOnClickListener(clickListener); btnAddAlias.setOnClickListener(clickListener); updateStatus(); mPushAgent.setPushIntentServiceClass(MyPushIntentService.class); callbackReceiver = new CallbackReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction(MyApplication.CALLBACK_RECEIVER_ACTION); registerReceiver(callbackReceiver, filter); }
From source file:biz.easymenu.easymenung.LoginFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { v = li.inflate(R.layout.logindialog, container, false); WindowManager.LayoutParams WMLP = this.getDialog().getWindow().getAttributes(); adultsNb = (NumberPicker) v.findViewById(R.id.adultnumpick); childrenNb = (NumberPicker) v.findViewById(R.id.childrennumpick); etPass = (EditText) v.findViewById(R.id.loginPass); pbar = (ProgressBar) v.findViewById(R.id.pBarLogin); btnOk = (Button) v.findViewById(R.id.lgnbtnOK); btnCancel = (Button) v.findViewById(R.id.lgnbtnCancel); btnDiners = (Button) v.findViewById(R.id.lgndinersbtnOK); btnDiners.setOnClickListener(new View.OnClickListener() { @Override//from w ww. ja va 2 s.c om public void onClick(View v) { new Thread(new DinersRun()).start(); } }); btnOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pbar.setVisibility(View.VISIBLE); new Thread(new NewSessionRun()).start(); } }); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); WMLP.y = 100; //y position WMLP.gravity = Gravity.TOP; WMLP.windowAnimations = R.style.PauseDialogAnimation; this.getDialog().getWindow().setAttributes(WMLP); this.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); //this.getDialog().getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation; spin = (AutoCompleteTextView) v.findViewById(R.id.spinnerLogin); adapter = new ArrayAdapter<String>(getActivity(), R.layout.autocompleteview, items); spin.setAdapter(adapter); spin.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { if (count == 1 && start == 0) { pbar.setVisibility(View.VISIBLE); new Thread(new LoadItemsRun()).start(); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } public void afterTextChanged(Editable s) { } }); return v; }
From source file:io.github.sunggu.searchimage.ui.ImageGridFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.image_search_fragment, container, false); edtSearchKeyword = (EditText) v.findViewById(R.id.search_keyword); edtSearchKeyword.addTextChangedListener(new TextWatcher() { @Override/*from ww w. java2 s .c om*/ 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) { OpenApi.getInstance().requestSearchImage(s.toString(), mResponseListener, mErrorListener); } }); final GridView mGridView = (GridView) v.findViewById(R.id.search_result_grid); mGridView.setAdapter(mAdapter); mGridView.setOnItemClickListener(this); mGridView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int scrollState) { // Pause fetcher to ensure smoother scrolling when flinging if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) { // Before Honeycomb pause image loading on scroll to help with performance if (!Utils.hasHoneycomb()) { mImageFetcher.setPauseWork(true); } } else { mImageFetcher.setPauseWork(false); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); // This listener is used to get the final width of the GridView and then calculate the // number of columns and the width of each column. The width of each column is variable // as the GridView has stretchMode=columnWidth. The column width is used to set the height // of each view so we get nice square thumbnails. mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @TargetApi(VERSION_CODES.JELLY_BEAN) @Override public void onGlobalLayout() { if (mAdapter.getNumColumns() == 0) { final int numColumns = (int) Math .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing)); if (numColumns > 0) { final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing; mAdapter.setNumColumns(numColumns); mAdapter.setItemHeight(columnWidth); if (BuildConfig.DEBUG) { Log.d(TAG, "onCreateView - numColumns set to " + numColumns); } if (Utils.hasJellyBean()) { mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } else { mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } } } } }); return v; }
From source file:com.android.projectz.teamrocket.thebusapp.activities.SearchLineActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { this.setTheme(getResources().getIdentifier(SharedPreferencesUtils.getSelectedTheme(this), "style", getPackageName()));//from w w w . j a v a 2 s.c o m super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_line); Toolbar toolbarSearchLine = (Toolbar) findViewById(R.id.toolbarSearchLine); setSupportActionBar(toolbarSearchLine); getSupportActionBar().setTitle(R.string.title_search_line); getSupportActionBar().setSubtitle(R.string.subtitle_search_line); getSupportActionBar().setDisplayHomeAsUpEnabled(true); ListView listView = (ListView) findViewById(R.id.fullBusList); String[] listText = { "Belluno - Santa Giustina - Feltre", "Belluno - Mel - Feltre", "Belluno - Vittorio Veneto", "Belluno - Feltre - Trento", "Linea BLU", "Linea CELESTE", "Linea LILLA", "Linea GIALLA", "Linea ROSSA", "Linea VERDE" }; final String[] url = { "http://dolomitibus.it/files/orari/2016-invernale/Extra/Feltrino/LINEA13_I.pdf", "http://dolomitibus.it/files/orari/2016-invernale/Extra/Feltrino/LINEA20_I.pdf", "http://dolomitibus.it/files/orari/2016-invernale/Extra/Bellunese/LINEA41_I.pdf", "http://dolomitibus.it/files/orari/2016-invernale/Extra/Feltrino/Linea20-27_Trento_I.pdf", "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950B_I.pdf", "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950C_I.pdf", "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950J_I.pdf", "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950L_I.pdf", "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950R_I.pdf", "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950V_I.pdf" }; adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listText); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { startBrowser(url[position]); } }); /** * questa editText fatta per filtrare le linee */ EditText editText = (EditText) findViewById(R.id.inputSearch); editText.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) { SearchLineActivity.this.adapter.getFilter().filter(s); } @Override public void afterTextChanged(Editable s) { } }); }
From source file:com.nxt.njitong.ContactlistActivity.java
public void initviews() { //super.onActivityCreated(savedInstanceState); //T??home???appcrash //if(savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) // return;//from www. j a v a 2 s . c o m context = this; findViewById(R.id.back).setVisibility(View.VISIBLE); ((TextView) findViewById(R.id.message_title)).setText(getIntent().getStringExtra("type")); inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); listView = (ListView) findViewById(R.id.list); sidebar = (Sidebar) findViewById(R.id.sidebar); sidebar.setListView(listView); //??? blackList = EMContactManager.getInstance().getBlackListUsernames(); contactList = new ArrayList<User>(); // ?contactlist getContactList(); //? query = (EditText) findViewById(R.id.query); String strSearch = getResources().getString(R.string.search); query.setHint(strSearch); clearSearch = (ImageButton) findViewById(R.id.search_clear); query.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s); if (s.length() > 0) { clearSearch.setVisibility(View.VISIBLE); } else { clearSearch.setVisibility(View.INVISIBLE); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable s) { } }); clearSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { query.getText().clear(); } }); // adapter adapter = new ContactAdapter(context, R.layout.row_contact, contactList); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String username = adapter.getItem(position).getUsername(); if (Constant.NEW_FRIENDS_USERNAME.equals(username)) { // ? User user = DemoApplication.getInstance().getContactList().get(Constant.NEW_FRIENDS_USERNAME); user.setUnreadMsgCount(0); startActivity(new Intent(context, NewFriendsMsgActivity.class)); } else if (Constant.GROUP_USERNAME.equals(username)) { // ?? startActivity(new Intent(context, GroupsActivity.class)); } else { // demo?? startActivity(new Intent(context, ChatActivity.class).putExtra("userId", adapter.getItem(position).getUsername())); } } }); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ?? if (getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); ImageView addContactView = (ImageView) findViewById(R.id.iv_new_contact); addContactView.setVisibility(View.GONE); // ? addContactView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(context, AddContactActivity.class)); } }); registerForContextMenu(listView); }
From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.common.DialogEditList.java
void setup() { // New item hides delete button and disables OK initially if (getArguments().getLong(LIST_ID, -1) < 1) { binding.deleteButton.setVisibility(View.GONE); binding.buttons.dialogYes.setEnabled(false); }/*from www . j a v a2 s . co m*/ if (getArguments().getLong(LIST_ID, -1) > 0) { getDialog().setTitle(R.string.menu_managelists); getLoaderManager().restartLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { return new CursorLoader(getActivity(), TaskList.getUri(getArguments().getLong(LIST_ID, -1)), TaskList.Columns.FIELDS, null, null, null); } @Override public void onLoadFinished(Loader<Cursor> arg0, Cursor c) { if (c.moveToFirst()) { mTaskList = new TaskList(c); fillViews(); } // Don't need it anymore getLoaderManager().destroyLoader(0); } @Override public void onLoaderReset(Loader<Cursor> arg0) { } }); } else { getDialog().setTitle(R.string.menu_createlist); mTaskList = new TaskList(); } binding.titleField.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { binding.buttons.dialogYes.setEnabled(editable.length() > 0); } }); binding.deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { deleteClicked(); } }); binding.buttons.dialogNo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dismiss(); } }); binding.buttons.dialogYes.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { okClicked(); } }); }
From source file:click.kobaken.rxirohaandroid_sample.presenter.AssetReceivePresenter.java
public TextWatcher textWatcher() { return new TextWatcher() { private boolean isAmountEmpty; @Override// ww w .j a v a 2 s . c o m public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { String amount = assetReceiveView.getAmount(); isAmountEmpty = amount == null || amount.isEmpty(); } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (isAmountEmpty && charSequence.toString().equals("0")) { assetReceiveView.setAmount(""); return; } changeQR(); } @Override public void afterTextChanged(Editable editable) { // nothing } }; }
From source file:de.greenrobot.daoexample.NoteActivity.java
protected void addUiListeners() { editText.setOnEditorActionListener(new OnEditorActionListener() { @Override/*from ww w . j ava 2s . c o m*/ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { addNote(); return true; } return false; } }); final View button = findViewById(R.id.buttonAdd); button.setEnabled(false); editText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { boolean enable = s.length() != 0; button.setEnabled(enable); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); mBtnAddAll.setOnClickListener(this); mBtnDeleteAll.setOnClickListener(this); mBtnDeleteByCount.setOnClickListener(this); mBtnQueryCount.setOnClickListener(this); mBtnQueryAll.setOnClickListener(this); mBtnQueryWithParam.setOnClickListener(this); }
From source file:com.app.blockydemo.ui.dialogs.ScriptNameDialog.java
private void handleOnShow(final Dialog dialogEditName) { final Button positiveButton = ((AlertDialog) dialogEditName).getButton(AlertDialog.BUTTON_POSITIVE); positiveButton.setEnabled(false);/*from w w w . j av a 2 s. co m*/ EditText dialogEditText = (EditText) dialogEditName.findViewById(R.id.dialog_editor_script_name_edit_text); InputMethodManager inputMethodManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.showSoftInput(dialogEditText, InputMethodManager.SHOW_IMPLICIT); dialogEditText.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 editable) { String variableName = editable.toString(); positiveButton.setEnabled(true); for (Script local_script : ProjectManager.getInstance().getCurrentSprite().getScriptList()) { if (local_script.getName().equals(variableName) && !local_script.getName().equals(script.getName())) { Toast.makeText(getActivity(), R.string.formula_editor_existing_variable, Toast.LENGTH_SHORT) .show(); positiveButton.setEnabled(false); } } if (editable.length() == 0) { positiveButton.setEnabled(false); } if (editable.toString().equals(script.getName())) { positiveButton.setEnabled(false); } } }); dialogEditText.setText(script.getName()); }