List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:ca.rmen.android.scrumchatter.dialog.InputDialogFragment.java
@Override @NonNull// ww w . j a va 2 s .c o m public Dialog onCreateDialog(Bundle savedInstanceState) { Log.v(TAG, "onCreateDialog: savedInstanceState = " + savedInstanceState); if (savedInstanceState != null) mEnteredText = savedInstanceState.getString(DialogFragmentFactory.EXTRA_ENTERED_TEXT); Bundle arguments = getArguments(); final int actionId = arguments.getInt(DialogFragmentFactory.EXTRA_ACTION_ID); final InputDialogEditTextBinding binding = DataBindingUtil.inflate(LayoutInflater.from(getActivity()), R.layout.input_dialog_edit_text, null, false); final Bundle extras = arguments.getBundle(DialogFragmentFactory.EXTRA_EXTRAS); final Class<?> inputValidatorClass = (Class<?>) arguments .getSerializable(DialogFragmentFactory.EXTRA_INPUT_VALIDATOR_CLASS); final String prefilledText = arguments.getString(DialogFragmentFactory.EXTRA_ENTERED_TEXT); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(arguments.getString(DialogFragmentFactory.EXTRA_TITLE)); builder.setView(binding.getRoot()); binding.edit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS); binding.edit.setHint(arguments.getString(DialogFragmentFactory.EXTRA_INPUT_HINT)); binding.edit.setText(prefilledText); if (!TextUtils.isEmpty(mEnteredText)) binding.edit.setText(mEnteredText); // Notify the activity of the click on the OK button. OnClickListener listener = null; if ((getActivity() instanceof DialogInputListener)) { listener = (dialog, which) -> { FragmentActivity activity = getActivity(); if (activity == null) Log.w(TAG, "User clicked on dialog after it was detached from activity. Monkey?"); else ((DialogInputListener) activity).onInputEntered(actionId, binding.edit.getText().toString(), extras); }; } builder.setNegativeButton(android.R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, listener); final AlertDialog dialog = builder.create(); // Show the keyboard when the EditText gains focus. binding.edit.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { Window window = dialog.getWindow(); if (window != null) { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); final Context context = getActivity(); try { final InputValidator validator = inputValidatorClass == null ? null : (InputValidator) inputValidatorClass.newInstance(); Log.v(TAG, "input validator = " + validator); // Validate the text as the user types. binding.edit.addTextChangedListener(new TextWatcher() { @Override 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) { mEnteredText = binding.edit.getText().toString(); if (validator != null) validateText(context, dialog, binding.edit, validator, actionId, extras); } }); dialog.setOnShowListener(dialogInterface -> { Log.v(TAG, "onShow"); validateText(context, dialog, binding.edit, validator, actionId, extras); }); } catch (Exception e) { Log.e(TAG, "Could not instantiate validator " + inputValidatorClass + ": " + e.getMessage(), e); } return dialog; }
From source file:com.happynetwork.vrestate.activitys.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter//from w w w . j a v a2s. 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(BaseApplication.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.app.khclub.base.easeim.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = ((KHHXSDKHelper) HXSDKHelper.getInstance()).getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter/*w ww. j a va2s.com*/ 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(KHUtils.selfCommonIMID())) Toast.makeText(getActivity(), st, 0).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.example.chudong.telescope.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter//from ww w. j a v a2s. co 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(MyApplication.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.easemob.appstoremedical.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter/* www .j a v a2s .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(AppMedicalApplication.getInstance().getUserName())) Toast.makeText(getActivity(), st, 0).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.giovanniterlingen.windesheim.view.Fragments.ChooseScheduleFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_choose_schedule, container, false); TextView chooseTextview = view.findViewById(R.id.choose_textview); TextView descriptionTextview = view.findViewById(R.id.description_textview); EditText dataSearch = view.findViewById(R.id.filter_edittext); if (type == 1) { chooseTextview.setText(getResources().getString(R.string.choose_class)); descriptionTextview.setText(getResources().getString(R.string.choose_class_description)); dataSearch.setHint(getResources().getString(R.string.choose_class_hint)); }/*from w w w.j a v a2s .c o m*/ if (type == 2) { chooseTextview.setText(getResources().getString(R.string.choose_teacher)); descriptionTextview.setText(getResources().getString(R.string.choose_teacher_description)); dataSearch.setHint(getResources().getString(R.string.choose_teacher_hint)); } if (type == 3) { chooseTextview.setText(getResources().getString(R.string.choose_subject)); descriptionTextview.setText(getResources().getString(R.string.choose_subject_description)); dataSearch.setHint(getResources().getString(R.string.choose_subject_hint)); } recyclerView = view.findViewById(R.id.recyclerview); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); spinner = view.findViewById(R.id.progress_bar); dataSearch.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { if (adapter != null) { adapter.filter(arg0.toString()); } } public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } public void afterTextChanged(Editable s) { } }); if (!isViewShown) { startTask(); } return view; }
From source file:com.lanou.lovemovie.dock.chat.HXChat.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter// w w w . ja va 2 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(AppApplication.getInstance().getUserName())) Toast.makeText(getActivity(), st, 0).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:cn.ucai.yizhesale.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorText = (TextView) errorItem.findViewById(cn.ucai.yizhesale.R.id.tv_connect_errormsg); // contact list contactList = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList(); listView = (ListView) getView().findViewById(cn.ucai.yizhesale.R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter// w w w . j a v a 2 s . com listView.setAdapter(adapter); final String st = getResources().getString(cn.ucai.yizhesale.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(YiZheSaleApplication.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(cn.ucai.yizhesale.R.id.query); // ?button clearSearch = (ImageButton) getView().findViewById(cn.ucai.yizhesale.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.jecelyin.android.file_explorer.FileListPagerFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { action = new FileExplorerAction(getContext(), this, ((FileExplorerActivity) getActivity()).getFileClipboard(), this); adapter = new FileListItemAdapter(); adapter.setOnCheckedChangeListener(action); adapter.setOnItemClickListener(this); adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override/* w ww. ja v a 2 s . c o m*/ public void onChanged() { binding.emptyLayout.post(new Runnable() { @Override public void run() { binding.emptyLayout.setVisibility(adapter.getItemCount() > 0 ? View.GONE : View.VISIBLE); } }); } }); binding.pathScrollView .setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); pathAdapter = new PathButtonAdapter(); pathAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onChanged() { binding.pathScrollView.scrollToPosition(pathAdapter.getItemCount() - 1); } }); pathAdapter.setPath(path); pathAdapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(int position, View view) { JecFile file = pathAdapter.getItem(position); switchToPath(file); } }); binding.pathScrollView.setAdapter(pathAdapter); binding.explorerSwipeRefreshLayout.setOnRefreshListener(this); binding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); binding.recyclerView.setAdapter(adapter); 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) { adapter.filter(s); } @Override public void afterTextChanged(Editable s) { } }); onRefresh(); Pref.getInstance(getContext()).registerOnSharedPreferenceChangeListener(this); }
From source file:cn.ucai.fulicenter.fragment.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter//ww w. ja va2s . 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(FuLiCenterApplication.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(); } }); }