List of usage examples for android.view.inputmethod InputMethodManager HIDE_NOT_ALWAYS
int HIDE_NOT_ALWAYS
To view the source code for android.view.inputmethod InputMethodManager HIDE_NOT_ALWAYS.
Click Source Link
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 ww w.j a v a 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:im.neon.activity.MXCActionBarActivity.java
/** * Dismiss the soft keyboard if one view in the activity has the focus. * @param activity the activity//from ww w . j av a2s .c om */ public static void dismissKeyboard(Activity activity) { // hide the soft keyboard View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager inputManager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } }
From source file:com.opensource.wheel.demo.base.BaseActivity.java
/** * ??/*from w w w . j a v a 2 s.co m*/ * @param view */ protected void hideKeyboard(View view) { InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); }
From source file:com.xpple.jahoqy.ui.activity.GroupsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_groups); 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 . jav a 2s. co m*/ 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) { // return; } // if (position == 1) { // // ? // startActivityForResult(new Intent(GroupsActivity.this, NewGroupActivity.class), 0); // } // else if (position == 2) { // // // //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 - 1).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 = (View) 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); } refresh(); }
From source file:com.barak.pix.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 w w w. java2s.com*/ 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.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:Rangoli.testapp.Feed.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 www . j ava2 s . c om*/ protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) { Author author = comment.getAuthor(); viewHolder.commentAuthor.setText(author.getFull_name()); PicassoUtil.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("add text here"); 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(), "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.dongmihui.im.activity.GroupsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.em_fragment_groups); instance = this; inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); grouplist = EMClient.getInstance().groupManager().getAllGroups(); groupListView = (ListView) findViewById(R.id.list); //show group list groupAdapter = new GroupAdapter(this, 1, grouplist); groupListView.setAdapter(groupAdapter); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout); swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light, R.color.holo_red_light); //pull down to refresh swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override/*from w w w. j a v a2 s. c om*/ public void onRefresh() { new Thread() { @Override public void run() { try { EMClient.getInstance().groupManager().getJoinedGroupsFromServer(); handler.sendEmptyMessage(0); } catch (HyphenateException e) { e.printStackTrace(); handler.sendEmptyMessage(1); } } }.start(); } }); ivBack = (ImageView) findViewById(R.id.iv_back_contact); ivBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); groupListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == 1) { // create a new group TODO startActivityForResult(new Intent(GroupsActivity.this, ECNewGroupActivity.class), 0); // } else if (position == 2) { // join a public group TODO // startActivityForResult(new Intent(GroupsActivity.this, PublicGroupsActivity.class), 0); } else { // enter group chat Intent intent = new Intent(GroupsActivity.this, ECChatActivity.class); // it is group chat intent.putExtra("chatType", Constant.CHATTYPE_GROUP); intent.putExtra("userId", 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; } }); }
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 ww w . j a v a 2s. co 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/*w w w. j a v a2 s .co m*/ 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.ysls.imhere.fragment.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); mAddFriendView = (RelativeLayout) getView().findViewById(R.id.rl_add_friends_tips); constact = (Button) mAddFriendView.findViewById(R.id.btn_constact); constact.setOnClickListener(new OnClickListener() { @Override/*from ww w . j ava 2 s . com*/ public void onClick(View v) { startActivity(new Intent(getActivity(), AddContactActivity.class)); getActivity().overridePendingTransition(R.anim.activity_up, R.anim.fade_out); } }); // contact list contactList = MyApplication.getInstance().getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); if (adapter.getCount() == 0) { mAddFriendView.setVisibility(View.VISIBLE); listView.setVisibility(View.GONE); } // adapter 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(MyApplication.getInstance().getUserName())) Toast.makeText(getActivity(), "??", 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(); } }); }