List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:app.view.chat.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorItem = (RelativeLayout) getView().findViewById(R.id.rl_error_item); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = DemoApplication.getInstance().getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter/*from w ww. j a v a2s .c o m*/ listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EMContact emContact = adapter.getItem(position); if (adapter.getItem(position).getUsername().equals(DemoApplication.getInstance().getUsername())) Toast.makeText(getActivity(), "??", Toast.LENGTH_SHORT).show(); else { // ?? Intent intent = new Intent(getActivity(), ChatActivity.class); if (emContact instanceof EMGroup) { //it is group chat intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP); intent.putExtra("groupId", ((EMGroup) emContact).getGroupId()); } else { //it is single chat intent.putExtra("userId", emContact.getUsername()); } startActivity(intent); } } }); // ?? registerForContextMenu(listView); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ?? if (getActivity().getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getActivity().getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); // ? query = (EditText) getView().findViewById(R.id.query); // ?button clearSearch = (ImageButton) getView().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(); } }); }
From source file:fr.cph.chicago.core.fragment.BikeFragment.java
private void loadList() { if (bikeAdapter == null) { List<BikeStation> bikeStations = activity.getIntent().getExtras() .getParcelableArrayList(bundleBikeStations); if (bikeStations == null) { bikeStations = new ArrayList<>(); }//from www . java 2s.c o m bikeAdapter = new BikeAdapter(bikeStations); } bikeListView.setAdapter(bikeAdapter); filter.addTextChangedListener(new TextWatcher() { private List<BikeStation> bikeStations; @Override public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { bikeStations = new ArrayList<>(); } @Override public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { bikeStations.addAll(Stream.of(BikeFragment.this.bikeStations).filter( bikeStation -> StringUtils.containsIgnoreCase(bikeStation.getName(), s.toString().trim())) .collect(Collectors.toList())); } @Override public void afterTextChanged(final Editable s) { bikeAdapter.setBikeStations(this.bikeStations); bikeAdapter.notifyDataSetChanged(); } }); bikeListView.setVisibility(ListView.VISIBLE); filter.setVisibility(ListView.VISIBLE); loadingLayout.setVisibility(RelativeLayout.INVISIBLE); errorLayout.setVisibility(RelativeLayout.INVISIBLE); }
From source file:com.github.dfa.diaspora_android.activity.PodSelectionActivity.java
private void setListedPods(String[] listedPodsArr) { final ArrayList<String> listedPodsList = new ArrayList<>(); for (String pod : listedPodsArr) { listedPodsList.add(pod.toLowerCase()); }// w w w . ja va2s . c o m final ArrayAdapter<String> adapter = new ArrayAdapter<>(PodSelectionActivity.this, android.R.layout.simple_list_item_1, listedPodsList); // save index and top position int index = listPods.getFirstVisiblePosition(); View v = listPods.getChildAt(0); int top = (v == null) ? 0 : (v.getTop() - listPods.getPaddingTop()); listPods.setAdapter(adapter); listPods.setSelectionFromTop(index, top); adapter.getFilter().filter(editFilter.getText()); editFilter.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { (adapter).getFilter().filter(s.toString()); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable s) { } }); }
From source file:com.akalizakeza.apps.ishusho.activity.CommentsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_comments, container, false); RecyclerView mCommentsView = (RecyclerView) rootView.findViewById(R.id.comment_list); mEditText = (EditText) rootView.findViewById(R.id.editText); final Button sendButton = (Button) rootView.findViewById(R.id.send_comment); final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef); mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.activity_comments_item, CommentViewHolder.class, commentsRef) { @Override//from w w w . ja v a 2s .c o m protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) { Artist artist = comment.getArtist(); viewHolder.commentAuthor.setText(artist.getFull_name()); GlideUtil.loadProfileIcon(artist.getProfile_picture(), viewHolder.commentPhoto); viewHolder.authorRef = artist.getUid(); viewHolder.commentTime.setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp())); viewHolder.commentText.setText(comment.getText()); } }; sendButton.setEnabled(false); mEditText.setHint(R.string.new_comment_hint); mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) }); mEditText.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) { if (editable.length() > 0) { sendButton.setEnabled(true); } else { sendButton.setEnabled(false); } } }); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Clear input box and hide keyboard. final Editable commentText = mEditText.getText(); mEditText.setText(""); InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user == null) { Toast.makeText(getActivity(), R.string.user_logged_out_error, Toast.LENGTH_SHORT).show(); } Artist artist = new Artist(user.getDisplayName(), user.getPhotoUrl().toString(), user.getUid()); Comment comment = new Comment(artist, commentText.toString(), ServerValue.TIMESTAMP); commentsRef.push().setValue(comment, new DatabaseReference.CompletionListener() { @Override public void onComplete(DatabaseError error, DatabaseReference firebase) { if (error != null) { Log.w(TAG, "Error posting comment: " + error.getMessage()); Toast.makeText(getActivity(), "Error posting comment.", Toast.LENGTH_SHORT).show(); mEditText.setText(commentText); } } }); } }); mCommentsView.setLayoutManager(new LinearLayoutManager(getActivity())); mCommentsView.setAdapter(mAdapter); return rootView; }
From source file:com.edicon.firebase.devs.firepix.CommentsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_comments, container, false); RecyclerView mCommentsView = (RecyclerView) rootView.findViewById(R.id.comment_list); mEditText = (EditText) rootView.findViewById(R.id.editText); final Button sendButton = (Button) rootView.findViewById(R.id.send_comment); final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef); mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.comment_item, CommentViewHolder.class, commentsRef) { @Override/*from ww w . j a va 2 s . c om*/ protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) { Author author = comment.getAuthor(); viewHolder.commentAuthor.setText(author.getFull_name()); GlideUtil.loadProfileIcon(author.getProfile_picture(), viewHolder.commentPhoto); viewHolder.authorRef = author.getUid(); viewHolder.commentTime.setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp())); viewHolder.commentText.setText(comment.getText()); } }; sendButton.setEnabled(false); mEditText.setHint(R.string.new_comment_hint); mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) }); mEditText.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) { if (editable.length() > 0) { sendButton.setEnabled(true); } else { sendButton.setEnabled(false); } } }); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Clear input box and hide keyboard. final Editable commentText = mEditText.getText(); mEditText.setText(""); InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user == null) { Toast.makeText(getActivity(), R.string.user_logged_out_error, Toast.LENGTH_SHORT).show(); } Author author = new Author(user.getDisplayName(), user.getPhotoUrl().toString(), user.getUid()); Comment comment = new Comment(author, commentText.toString(), ServerValue.TIMESTAMP); commentsRef.push().setValue(comment, new DatabaseReference.CompletionListener() { @Override public void onComplete(DatabaseError error, DatabaseReference firebase) { if (error != null) { Log.w(TAG, "Error posting comment: " + error.getMessage()); Toast.makeText(getActivity(), "Error posting comment.", Toast.LENGTH_SHORT).show(); mEditText.setText(commentText); } } }); } }); mCommentsView.setLayoutManager(new LinearLayoutManager(getActivity())); mCommentsView.setAdapter(mAdapter); return rootView; }
From source file:com.bofsoft.laio.customerservice.Fragment.CarListFragment.java
private void set_eSearch_TextChanged() { et_carlist_search.addTextChangedListener(new TextWatcher() { @Override//from w ww.j a v a 2 s.co m public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub //handler.post(eChanged); new Handler(Looper.getMainLooper()).post(eChanged); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub /**?? * ????listview??? * ?? */ if (s.length() == 0) { // ivDeleteText.setVisibility(View.GONE);//?? } else { // ivDeleteText.setVisibility(View.VISIBLE);//??? } } }); }
From source file:ansteph.com.beecabfordrivers.view.registration.RegistrationFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_registration, container, false); txtFullName = (EditText) rootView.findViewById(R.id.input_name); txtEmail = (EditText) rootView.findViewById(R.id.input_email); txtCompanyName = (EditText) rootView.findViewById(R.id.input_companyname); txtMobile = (EditText) rootView.findViewById(R.id.input_mobile); txtCarModel = (EditText) rootView.findViewById(R.id.input_model); txtNumPlate = (EditText) rootView.findViewById(R.id.input_plate); txtLicence = (EditText) rootView.findViewById(R.id.input_cablicence); txtYear = (EditText) rootView.findViewById(R.id.input_year); txtPassword = (EditText) rootView.findViewById(R.id.input_password); txtConPassword = (EditText) rootView.findViewById(R.id.input_confirm_password); imgValid = (ImageView) rootView.findViewById(R.id.imgValid); txtReg = (TextView) rootView.findViewById(R.id.txtRegistration); requestQueue = Volley.newRequestQueue(getActivity()); Button btnCreateAcc = (Button) rootView.findViewById(R.id.btn_signup); driverClass = ((Registration) getActivity()).getDriverClass(); txtConPassword.addTextChangedListener(new TextWatcher() { @Override/* w ww . ja va2s .com*/ 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) { String npwd = txtPassword.getText().toString().trim(); String cpwd = txtConPassword.getText().toString().trim(); if (!npwd.isEmpty() && npwd.length() == cpwd.length()) { if (npwd.equals(cpwd)) { //show the tick mark imgValid.setVisibility(View.VISIBLE); } else { //no show the tick mark imgValid.setVisibility(View.INVISIBLE); } } else { //no show the tick mark imgValid.setVisibility(View.INVISIBLE); } } }); txtPassword.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) { String npwd = txtPassword.getText().toString().trim(); String cpwd = txtConPassword.getText().toString().trim(); if (!npwd.isEmpty() && npwd.length() == cpwd.length()) { if (npwd.equals(cpwd)) { //show the tick mark imgValid.setVisibility(View.VISIBLE); } else { //no show the tick mark imgValid.setVisibility(View.INVISIBLE); } } else { //no show the tick mark imgValid.setVisibility(View.INVISIBLE); } } }); btnCreateAcc.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Do registration if (!isEmailOk()) { txtReg.setText(getString(R.string.invalid_email)); txtReg.setTextColor(Color.RED); return; } if (txtFullName.getText().toString().isEmpty() || txtMobile.getText().toString().isEmpty()) { txtReg.setText(getString(R.string.missing_info)); txtReg.setTextColor(Color.YELLOW); return; } if (txtPassword.getText().toString().length() < 6) { txtReg.setText(getString(R.string.pwd_short)); txtReg.setTextColor(Color.YELLOW); return; } if (imgValid.getVisibility() == View.VISIBLE) { //Do registration try { registerClient(); } catch (JSONException e) { e.printStackTrace(); } } else { txtReg.setText(getString(R.string.pwd_mismatch)); txtReg.setTextColor(Color.RED); } } }); return rootView; }
From source file:com.example.Bama.chat.chatuidemo.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorItem = (RelativeLayout) getView().findViewById(R.id.rl_error_item); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = HCApplication.getInstance().getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter//from w w w . j a v a2 s .c o m listView.setAdapter(adapter); final String st = getResources().getString(R.string.Cant_chat_with_yourself); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EMContact emContact = adapter.getItem(position); if (adapter.getItem(position).getUsername().equals(HCApplication.getInstance().getUserName())) Toast.makeText(getActivity(), st, Toast.LENGTH_SHORT).show(); else { // ?? Intent intent = new Intent(getActivity(), ChatActivity.class); if (emContact instanceof EMGroup) { //it is group chat intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP); intent.putExtra("groupId", ((EMGroup) emContact).getGroupId()); } else { //it is single chat intent.putExtra("userId", emContact.getUsername()); } startActivity(intent); } } }); // ?? registerForContextMenu(listView); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ?? if (getActivity().getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getActivity().getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); // ? query = (EditText) getView().findViewById(R.id.query); // ?button clearSearch = (ImageButton) getView().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(); } }); }
From source file:com.github.runoshun.in_app_survey.ui.QuestionFragment.java
protected View onCreateFreeWritingView(final FreeWritingQuestion question, LayoutInflater inflater, ViewGroup container, @SuppressWarnings("UnusedParameters") Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_default_freewriting, container, false); TextView questionView = (TextView) view.findViewById(R.id.survey_question); EditText answerView = (EditText) view.findViewById(R.id.survey_textarea); questionView.setText(question.question); answerView.addTextChangedListener(new TextWatcher() { @Override//from w w w . j a va 2 s . c o m 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) { Log.v("FreeWriting", "editable = " + editable.toString()); question.saveAnswer(editable.toString()); } }); return view; }
From source file:com.app.blockydemo.ui.dialogs.TextDialog.java
protected TextWatcher getInputTextChangedListener(final Button buttonPositive) { return new TextWatcher() { @Override//from w ww . j a v a2s. co m public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.length() == 0) { buttonPositive.setEnabled(false); } else { buttonPositive.setEnabled(true); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }; }