Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: How to detect click on custom SearchView element
    primarykey
    data
    text
    <p>I m creating a custom SearchView, but so far I didn't find a (click)event or listener, if the user clicks on the searchView widget. So SearchView is close, user clicks on the search Icon (which listener?!), SearchView is opened. See the picture below. I need that event, because I want to change the UI after user opens the searchView</p> <p><img src="https://i.stack.imgur.com/dMewY.png" alt="enter image description here"></p> <p><strong>EDIT:</strong> What I tried so far is</p> <ul> <li><p><code>setOnClickListener</code> to SearchView Element -> but it's only triggered if the SearchView is open(2nd picture) </p></li> <li><p>searched <code>SearchView</code> Api, but there isn't a listener for that action (or am I blind?)</p></li> <li><p>tried a workaround with <code>onWindowFocusChanged</code> of the searchView, but due the fact that the searchView is hidden in some kind of youtube/facebook sidebar, this doesn't work</p></li> </ul> <p>Any ideas? I attached my SearchView Code as well, but don't think the code is wrong. just no listener yet. btw: any workarounds are welcome. But it would be nice, if the SearchView is closed at the beginning! (like in the pictures above)</p> <pre><code>public class AmplifySearchView extends SearchView implements OnQueryTextListener, OnFocusChangeListener, OnCloseListener { private static final String DEBUG_TAG = "AmplifySeachView"; private Context context; private DataBaseController datasource; private StationListView searchResultListView; private TextView noResultTextView; private Boolean searchStarted = false; public AmplifySearchView(Context context) { super(context); this.context = context; } public AmplifySearchView(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; } public void initSearchView(StationListView view, TextView noResultTextView) { this.searchResultListView = view; this.searchResultListView.setActivityId(Constants.UI_SEARCH_RESULT_LIST); this.noResultTextView = noResultTextView; this.setOnQueryTextListener(this); this.setOnFocusChangeListener(this); this.setOnCloseListener(this); this.setOnCloseListener(this); setIconifiedByDefault(true); datasource = DataBaseController.getInstance(context); int id = this.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); TextView textView = (TextView) findViewById(id); textView.setTextColor(Color.WHITE); resetSearchInputTextField(); } private void resetSearchInputTextField() { setQueryHint(getResources().getString(R.string.search_hint)); } @Override public boolean onClose() { Log.d(DEBUG_TAG, "onClose()"); searchResultListView.setVisibility(View.GONE); noResultTextView.setVisibility(View.GONE); searchStarted = false; Intent intent = new Intent(Constants.SEARCH_ENDED); intent.addCategory(Constants.UI_AMPLIFY_CATEGORY); context.sendBroadcast(intent); return false; } @Override public void onFocusChange(View v, boolean hasFocus) { Log.d(DEBUG_TAG,"onFocusChange()" + hasFocus); } @Override public boolean onQueryTextChange(String newText) { //do sth... } @Override public boolean onQueryTextSubmit(String query) { Log.d(DEBUG_TAG, "onQueryTextSubmit -&gt; " + query); return true; } @Override protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { Log.d(DEBUG_TAG, "onQueryTextSubmit -&gt; " + gainFocus); // TODO Auto-generated method stub super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); } @Override public void onActionViewCollapsed() { Log.d(DEBUG_TAG, "onActionViewCollapsed"); super.onActionViewCollapsed(); } @Override public void onActionViewExpanded() { Log.d(DEBUG_TAG, "onActionViewExpanded"); super.onActionViewExpanded(); } } </code></pre> <p>btw: on Focus change don't work here, because searchview is invisible at the beginning and insert in the ui later...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload