List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:fr.cph.chicago.fragment.BikeFragment.java
private final void loadList() { EditText filter = (EditText) mRootView.findViewById(R.id.bike_filter); if (mAdapter == null) { mAdapter = new BikeAdapter(mActivity); }// w w w. j av a 2 s. c om mListView.setAdapter(mAdapter); filter.addTextChangedListener(new TextWatcher() { private List<BikeStation> bikeStations = null; @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { this.bikeStations = new ArrayList<BikeStation>(); } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { for (BikeStation bikeStation : BikeFragment.this.mBikeStations) { if (StringUtils.containsIgnoreCase(bikeStation.getName(), s.toString().trim())) { this.bikeStations.add(bikeStation); } } } @Override public void afterTextChanged(Editable s) { mAdapter.setBikeStations(this.bikeStations); mAdapter.notifyDataSetChanged(); } }); mListView.setVisibility(ListView.VISIBLE); mFilterView.setVisibility(ListView.VISIBLE); mLoadingLayout.setVisibility(RelativeLayout.INVISIBLE); RelativeLayout errorLayout = (RelativeLayout) mRootView.findViewById(R.id.error_layout); errorLayout.setVisibility(RelativeLayout.INVISIBLE); }
From source file:com.example.dadesheng.firebasesandbox.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Set default username is anonymous. mUsername = ANONYMOUS;/* w w w. jav a 2 s .c o m*/ // Initialize Firebase Auth mFirebaseAuth = FirebaseAuth.getInstance(); mFirebaseUser = mFirebaseAuth.getCurrentUser(); if (mFirebaseUser == null) { // Not signed in, launch the Sign In activity startActivity(new Intent(this, SignInActivity.class)); finish(); return; } else { mUsername = mFirebaseUser.getDisplayName(); if (mFirebaseUser.getPhotoUrl() != null) { mPhotoUrl = mFirebaseUser.getPhotoUrl().toString(); } } mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API).build(); // Initialize ProgressBar and RecyclerView. mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView); mLinearLayoutManager = new LinearLayoutManager(this); mLinearLayoutManager.setStackFromEnd(true); mMessageRecyclerView.setLayoutManager(mLinearLayoutManager); mProgressBar.setVisibility(ProgressBar.INVISIBLE); mMessageEditText = (EditText) findViewById(R.id.messageEditText); mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter( mSharedPreferences.getInt(CodelabPreferences.FRIENDLY_MSG_LENGTH, DEFAULT_MSG_LENGTH_LIMIT)) }); mMessageEditText.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) { if (charSequence.toString().trim().length() > 0) { mSendButton.setEnabled(true); } else { mSendButton.setEnabled(false); } } @Override public void afterTextChanged(Editable editable) { } }); mSendButton = (Button) findViewById(R.id.sendButton); mSendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Send messages on click. } }); }
From source file:com.manoj.fragments.SongCustomFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.song, container, false); mGridView = (ListView) v.findViewById(R.id.song_list); edittext = (EditText) v.findViewById(R.id.song_search); mGridView.setAdapter(mAdapter);// w w w . jav a2 s . c o m homeScreen = (LinearLayout) v.findViewById(R.id.song_layout); utilities.colorSeter(homeScreen, activity.getApplicationContext()); edittext.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { scroll = false; filteredSongMap.clear(); try { textlength = edittext.getText().length(); if (textlength == 0) { mAdapter = new ImageAdapter(getActivity(), songsListData); mGridView.setAdapter(mAdapter); } else { for (int i = 0; i < songsListData.size(); i++) { HashMap songMap = (HashMap) songsListData.get(i); String toFilterText = songMap.get("KEY_TITLE").toString(); if (textlength <= toFilterText.length()) { if (edittext.getText().toString() .equalsIgnoreCase((String) toFilterText.subSequence(0, textlength))) { filteredSongMap.add(songMap); } } } mAdapter = new ImageAdapter(getActivity(), filteredSongMap); mGridView.setAdapter(mAdapter); } } catch (Exception e) { Log.i("", e.toString()); } //mAdapter.songsListData = filteredSongMap; /*mAdapter = new ImageAdapter(getActivity(),filteredSongMap); ImageCacheParams cacheParams = new ImageCacheParams(getActivity(), IMAGE_CACHE_DIR); cacheParams.setMemCacheSizePercent(0.25f); // Set memory cache to 25% of app memory // The ImageFetcher takes care of loading images into our ImageView children asynchronously mImageFetcher = new ImageFetcher(getActivity(), mImageThumbSize,activity); mImageFetcher.setLoadingImage(R.drawable.adele); mImageFetcher.addImageCache(getActivity().getSupportFragmentManager(), cacheParams); */ /* for (int i = 0; i < text.length; i++) { if (textlength <= text[i].length()) { if (edittext.getText().toString(). equalsIgnoreCase((String) text[i].subSequence(0, textlength))) { text_sort.add(text[i]); image_sort.add(image[i]); } }*/ } }); mGridView.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int scrollState) { // Pause fetcher to ensure smoother scrolling when flinging if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) { mImageFetcher.setPauseWork(true); } else { mImageFetcher.setPauseWork(false); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); // select single listview item mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } }); // 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() { @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); } } } } });*/ return v; }
From source file:com.hzx.luoyechat.activity.GroupsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); inflateContentView(R.layout.fragment_groups, R.string.group_chat, true); instance = this; inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); grouplist = EMGroupManager.getInstance().getAllGroups(); groupListView = (ListView) findViewById(R.id.list); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout); swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override//from w w w . ja va 2 s . c om public void onRefresh() { MainActivity.asyncFetchGroupsFromServer(); } }); groupAdapter = new GroupAdapter(this, 1, grouplist); groupListView.setAdapter(groupAdapter); groupListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == 0) { // ? startActivityForResult(new Intent(GroupsActivity.this, NewGroupActivity.class), 0); } else if (position == 1) { // startActivityForResult(new Intent(GroupsActivity.this, PublicGroupsActivity.class), 0); } else { // ? Intent intent = new Intent(GroupsActivity.this, ChatActivity.class); // it is group chat intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP); intent.putExtra("groupId", groupAdapter.getItem(position - 2).getGroupId()); startActivityForResult(intent, 0); } } }); groupListView.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; } }); progressBar = findViewById(R.id.progress_bar); syncListener = new SyncListener(); HXSDKHelper.getInstance().addSyncGroupListener(syncListener); if (!HXSDKHelper.getInstance().isGroupsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } final EditText query = (EditText) findViewById(R.id.query); final ImageButton clearSearch = (ImageButton) findViewById(R.id.search_clear); query.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { groupAdapter.getFilter().filter(s); if (s.length() > 0) { clearSearch.setVisibility(View.VISIBLE); } else { clearSearch.setVisibility(View.GONE); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable s) { } }); clearSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { query.getText().clear(); } }); refresh(); }
From source file:com.gmail.taneza.ronald.carbs.main.FoodDetailsActivity.java
private void addQuantityTextListener() { mQuantityEditText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { // Abstract Method of TextWatcher Interface. }/*from ww w .ja va2 s . co m*/ public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Abstract Method of TextWatcher Interface. } public void onTextChanged(CharSequence s, int start, int before, int count) { Integer quantity = 0; try { quantity = Integer.parseInt(mQuantityEditText.getText().toString()); } catch (NumberFormatException e) { // ignore invalid quantity string } mFoodItemInfo.setQuantity(quantity); updateCarbsText(); } }); }
From source file:com.example.cuisoap.agrimac.homePage.machineDetail.driverInfoFragment.java
public void addTextWatcher() { driver_name.addTextChangedListener(new TextWatcher() { @Override//from ww w . ja v a 2s . c o m 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) { machineDetailData.driver_name = s.toString(); } }); driver_age.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) { machineDetailData.driver_age = s.toString(); } }); }
From source file:at.jclehner.rxdroid.preferences.DrugNamePreference2.java
@Override protected View onCreateDialogView() { mEditText = new AutoCompleteTextView(getContext()); mAutoCompleteAdapter = new ArrayAdapter<String>(this.getContext(), android.R.layout.simple_dropdown_item_1line); System.out.println("Initializing autocomplete..."); mEditText.setThreshold(3);//from w w w .j av a 2 s . co m mEditText.setAdapter(mAutoCompleteAdapter); mEditText.addTextChangedListener(new TextWatcher() { private boolean shouldAutoComplete = true; @Override public void onTextChanged(CharSequence s, int start, int before, int count) { shouldAutoComplete = true; for (int position = 0; position < mAutoCompleteAdapter.getCount(); position++) { if (mAutoCompleteAdapter.getItem(position).equalsIgnoreCase(s.toString())) { shouldAutoComplete = false; break; } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (shouldAutoComplete) { new DoAutoCompleteSearch().execute(s.toString()); } } }); // mEditText = new EditText(getContext()); mEditText.setText(getValue()); mEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS); //mEditText.setSelectAllOnFocus(true); mEditText.addTextChangedListener(mWatcher); return mEditText; }
From source file:com.javielinux.fragments.SearchGeoFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = View.inflate(getActivity(), R.layout.search_geo_fragment, null); useGeo = (CheckBox) view.findViewById(R.id.cb_use_geo); typeGeo = (RadioGroup) view.findViewById(R.id.rg_type_geo); typeGeoGPS = (RadioButton) view.findViewById(R.id.rb_use_gps); typeGeoMap = (RadioButton) view.findViewById(R.id.rb_use_map); typeDistance = (RadioGroup) view.findViewById(R.id.rg_type_distance); typeDistanceMiles = (RadioButton) view.findViewById(R.id.rb_distance_miles); typeDistanceKM = (RadioButton) view.findViewById(R.id.rb_distance_km); llLocation = (LinearLayout) view.findViewById(R.id.ll_location); llMap = (LinearLayout) view.findViewById(R.id.ll_map); llDistance = (LinearLayout) view.findViewById(R.id.ll_distance); place = (AutoCompleteTextView) view.findViewById(R.id.et_place); address_list = new ArrayList<Address>(); address_adapter = new AddressAdapter(getActivity(), address_list); place.setAdapter(address_adapter);/*from w w w.java 2s . c om*/ place.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { Address address = address_adapter.getAddressItem(i); if (address != null) { latitude.setText(String.valueOf(address.getLatitude())); longitude.setText(String.valueOf(address.getLongitude())); } } }); latitude = (EditText) view.findViewById(R.id.et_latitude); longitude = (EditText) view.findViewById(R.id.et_longitude); distance = (SeekBar) view.findViewById(R.id.sb_distance); distanceTxt = (TextView) view.findViewById(R.id.distance); distance.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { changeTextDistance(arg1); } @Override public void onStartTrackingTouch(SeekBar arg0) { } @Override public void onStopTrackingTouch(SeekBar arg0) { } }); useGeo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { showFields(); } else { hideFields(); } } }); typeGeoGPS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { hideFieldsMap(); } } }); typeGeoMap.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { showFieldsMap(); } } }); typeDistanceMiles.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { reloadTextDistance(); } }); typeDistanceKM.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { reloadTextDistance(); } }); place.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { String currentText = place.getText().toString(); if (currentText.length() >= 3) APITweetTopics.execute(getActivity(), getLoaderManager(), SearchGeoFragment.this, new GetGeolocationAddressRequest(getActivity(), currentText, false)); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable editable) { } }); populateFields(); return view; }
From source file:com.duy.pascal.ui.file.fragment.FileListPagerFragment.java
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); FileClipboard fileClipboard = ((FileActionListener) getActivity()).getFileClipboard(); mAction = new FileExplorerAction(getContext(), this, fileClipboard, this); mAdapter = new FileListItemAdapter(); mAdapter.setOnCheckedChangeListener(mAction); mAdapter.setOnItemClickListener(this); mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override//from w ww .jav a2 s . c o m public void onChanged() { binding.emptyLayout.post(new Runnable() { @Override public void run() { binding.emptyLayout.setVisibility(mAdapter.getItemCount() > 0 ? View.GONE : View.VISIBLE); } }); } }); binding.pathScrollView .setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); mPathAdapter = new PathButtonAdapter(); mPathAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onChanged() { binding.pathScrollView.scrollToPosition(mPathAdapter.getItemCount() - 1); } }); mPathAdapter.setPath(mPath); mPathAdapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(int position, View view) { File file = mPathAdapter.getItem(position); switchToPath(file); } @Override public boolean onItemLongClick(int position, View view) { return false; } }); binding.pathScrollView.setAdapter(mPathAdapter); binding.explorerSwipeRefreshLayout.setOnRefreshListener(this); binding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); binding.recyclerView.setAdapter(mAdapter); binding.recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(getContext()) .margin(getResources().getDimensionPixelSize(R.dimen.file_list_item_divider_left_margin), 0) .build()); binding.explorerSwipeRefreshLayout.post(new Runnable() { @Override public void run() { binding.explorerSwipeRefreshLayout.setRefreshing(true); } }); binding.nameFilterEditText.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) { mAdapter.filter(s); } @Override public void afterTextChanged(Editable s) { } }); onRefresh(); }
From source file:com.activiti.android.ui.fragments.form.picker.IdmPickerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (getArguments() != null) { onRetrieveParameters(getArguments()); }/*from w w w.j av a 2 s . c o m*/ // Create View setRootView(inflater.inflate(R.layout.fr_idm_picker, container, false)); // Init list init(getRootView(), emptyListMessageId); gv.setChoiceMode(GridView.CHOICE_MODE_SINGLE); setListShown(true); searchView = UIUtils.setActionBarCustomView(getActivity(), R.layout.person_picker_header, true); View searchBack = searchView.findViewById(R.id.search_back); searchBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getActivity().getSupportFragmentManager().popBackStackImmediate(); } }); if (keywords != null && !keywords.isEmpty()) { search(keywords); } else { // Speech to Text hasTextToSpeech = FeatureUtils.hasSpeechToText(getActivity()); speechToText = (ImageButton) searchView.findViewById(R.id.search_microphone); if (hasTextToSpeech) { speechToText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { speechToText(); } }); } else { speechToText.setVisibility(View.GONE); } searchAction = (ImageButton) searchView.findViewById(R.id.search_start); searchAction.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (searchForm.getText().length() > 0) { keywords = searchForm.getText().toString(); search(keywords); } else { // TODO Snackbar } } }); searchAction.setVisibility(View.GONE); // Init form search searchForm = (EditText) searchView.findViewById(R.id.search_query); searchForm.requestFocus(); UIUtils.showKeyboard(getActivity(), searchForm); searchForm.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchForm.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) { searchAction.setVisibility(View.GONE); if (hasTextToSpeech) { speechToText.setVisibility(View.VISIBLE); } } else { speechToText.setVisibility(View.GONE); searchAction.setVisibility(View.VISIBLE); } } }); searchForm.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN) && ((actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) || (actionId == EditorInfo.IME_ACTION_DONE))) { if (searchForm.getText().length() > 0) { keywords = searchForm.getText().toString(); search(keywords); } else { // TODO Snackbar } return true; } return false; } }); } if (getMode() == MODE_PICK) { Button cancel = UIUtils.initCancel(getRootView(), R.string.general_action_cancel); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (getDialog() != null) { getDialog().dismiss(); } else { getFragmentManager().popBackStack(); } } }); } else { hide(R.id.validation_panel); } return getRootView(); }