Example usage for android.widget SearchView findViewById

List of usage examples for android.widget SearchView findViewById

Introduction

In this page you can find the example usage for android.widget SearchView findViewById.

Prototype

@Nullable
public final <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID, the view itself if the ID matches #getId() , or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

Usage

From source file:Main.java

public static void customActionBarSearchViewTextColor(SearchView searchView) {
    int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
    TextView textView = (TextView) searchView.findViewById(id);
    textView.setTextColor(Color.WHITE);
}

From source file:com.github.rutvijkumar.twittfuse.Util.java

public static void setupSearchView(final Activity activity, final SearchView searchView) {

    int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null,
            null);/*from  w  w w.jav a  2  s . c  om*/
    EditText searchPlate = (EditText) searchView.findViewById(searchPlateId);
    searchPlate.setTextColor(activity.getResources().getColor(android.R.color.white));
    searchView.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            boolean isValidSubmit = false;
            if (query != null && !query.isEmpty()) {
                search(activity, query);
                isValidSubmit = true;
            }

            return isValidSubmit;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // TODO Auto-generated method stub
            return false;
        }
    });
}

From source file:edu.ucsb.cs.cs185.inspirante.searchbyranking.SearchByRankingFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_search_by_ranking, container, false);

    final SearchView searchView = (SearchView) rootView.findViewById(R.id.search_by_ranking_search_view);
    int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
    EditText searchEditText = (EditText) searchView.findViewById(id);
    searchEditText.setTextColor(Color.GRAY);
    searchEditText.setHintTextColor(Color.GRAY);
    searchView.setOnQueryTextListener(searchViewListener);
    searchView.setMaxWidth(Integer.MAX_VALUE);
    searchView.setOnClickListener(new View.OnClickListener() {

        @Override//from  w w  w . j a v a  2 s .c o  m
        public void onClick(View view) {
            searchView.setFocusable(true);
            searchView.setIconified(false);
            searchView.requestFocusFromTouch();
        }
    });

    mInspireRecyclerView = (RecyclerView) rootView.findViewById(R.id.search_rv);
    mInspireRecyclerView.setHasFixedSize(true);
    mInspireRecyclerView.setNestedScrollingEnabled(false);

    frequentTags = ItemCards.getInstance(getContext()).getFrequentTags();

    mInspireAdapter = new RankByTagAdapter(getContext(), this, frequentTags);
    mInspireAdapter.setHasStableIds(true);

    mLayoutManager = new LinearLayoutManager(getContext());
    mLayoutManager.setItemPrefetchEnabled(true);

    mInspireRecyclerView.setLayoutManager(mLayoutManager);

    mInspireAdapter.setOnItemClickListener(new RankByTagAdapter.OnRecyclerViewItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            TextView tv = (TextView) view;
            Intent intent = new Intent(getActivity(), TagAndImagesActivity.class);
            intent.putExtra("TAG", tv.getText());
            startActivity(intent);
        }
    });

    ItemCards itemCards = ItemCards.getInstance(getContext());
    itemCards.setAdapter(mInspireAdapter);

    mInspireRecyclerView.setAdapter(mInspireAdapter);
    mInspireAdapter.notifyDataSetChanged();

    // Set Tag recycler view
    mTagRecyclerView = (RecyclerView) rootView.findViewById(R.id.search_tags_rv);
    mTagRecyclerView.setHasFixedSize(true);
    mTagRecyclerView.setNestedScrollingEnabled(false);
    mTagsAdapter = new TagsAdapter(getContext(), frequentTags);
    mTagsAdapter.setHasStableIds(true);
    RecyclerView.LayoutManager tagsLayoutManager = new LinearLayoutManager(getContext(),
            LinearLayoutManager.HORIZONTAL, false);
    tagsLayoutManager.setItemPrefetchEnabled(true);

    mTagRecyclerView.setLayoutManager(tagsLayoutManager);

    mTagsAdapter.setOnItemClickListener(new TagsAdapter.OnRecyclerViewItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            String tag = mTagsAdapter.getTag(position);
            searchViewListener.onQueryTextChange(tag);
            //searchView.setFocus
            searchView.setQuery(tag, true);
            searchView.setIconified(false);
            searchView.clearFocus();
            mLayoutManager.scrollToPosition(0);

        }
    });

    mTagRecyclerView.setAdapter(mTagsAdapter);
    mTagsAdapter.notifyDataSetChanged();

    return rootView;
}

From source file:com.sage42.androidappaddicts.app.main.MainActivity.java

private void setSearchTextColour(final SearchView searchView) {
    final int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", //$NON-NLS-1$
            null, null);/*from  w  w  w .j  av  a 2s  .  c om*/
    final EditText searchPlate = (EditText) searchView.findViewById(searchPlateId);
    searchPlate.setHintTextColor(this.getResources().getColor(R.color.white));
}

From source file:jm.org.data.area.IndicatorActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem searchViewMenuItem = menu.findItem(R.id.menu_search);
    SearchView mSearchView = (SearchView) searchViewMenuItem.getActionView();
    int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
    ImageView v = (ImageView) mSearchView.findViewById(searchImgId);
    v.setImageResource(R.drawable.ic_action_search);
    return super.onPrepareOptionsMenu(menu);
}

From source file:ca.appvelopers.mcgillmobile.ui.MapActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.search, menu);

    // Get the SearchView
    MenuItem item = menu.findItem(R.id.action_search);
    Assert.assertNotNull(getSupportActionBar());
    final SearchView searchView = new SearchView(this);
    final int textViewID = searchView.getContext().getResources().getIdentifier("android:id/search_src_text",
            null, null);/*from  w w  w .  j ava2  s  .  c  om*/
    final AutoCompleteTextView searchTextView = (AutoCompleteTextView) searchView.findViewById(textViewID);
    try {
        // Set the cursor to the same color as the text
        Field cursorDrawable = TextView.class.getDeclaredField("mCursorDrawableRes");
        cursorDrawable.setAccessible(true);
        cursorDrawable.set(searchTextView, 0);
    } catch (Exception e) {
        Timber.e(e, "Cannot change color of cursor");
    }

    // Set up the query listener
    MenuItemCompat.setActionView(item, searchView);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            searchString = query;
            filterBySearchString();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            searchString = newText;
            filterBySearchString();
            return false;
        }
    });

    //Reset the search view
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            searchString = "";
            filterBySearchString();
            return false;
        }
    });

    return true;
}

From source file:org.jitsi.android.gui.contactlist.ContactListFragment.java

/**
 * {@inheritDoc}/*www  . j ava  2s .c  om*/
 */
@Override
public void onResume() {
    super.onResume();

    contactListView.setAdapter(getContactListAdapter());

    // Attach contact groups expand memory
    listExpandHandler = new MetaGroupExpandHandler(contactListAdapter, contactListView);
    listExpandHandler.bindAndRestore();

    // Update active chats
    contactListAdapter.invalidateViews();

    // Restore search state based on entered text
    if (searchItem != null) {
        SearchView searchView = (SearchView) searchItem.getActionView();
        int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        TextView textView = (TextView) searchView.findViewById(id);

        filterContactList(textView.getText().toString());

        bindSearchListener();
    }

    // Restore scroll position
    contactListView.setSelectionFromTop(scrollPosition, scrollTopPosition);
}

From source file:org.jitsi.android.gui.contactlist.ContactListFragment.java

/**
 * Invoked when the options menu is created. Creates our own options menu
 * from the corresponding xml./* ww  w  .j  a  v a2  s .  c  om*/
 *
 * @param menu the options menu
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
    super.onCreateOptionsMenu(menu, menuInflater);

    Activity activity = getActivity();

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);

    this.searchItem = menu.findItem(R.id.search);

    // OnActionExpandListener not supported prior API 14
    if (AndroidUtils.hasAPI(14)) {
        searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
                filterContactList("");

                return true; // Return true to collapse action view
            }

            public boolean onMenuItemActionExpand(MenuItem item) {
                return true; // Return true to expand action view
            }
        });
    }

    if (AndroidUtils.hasAPI(11)) {
        SearchView searchView = (SearchView) searchItem.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));

        int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        TextView textView = (TextView) searchView.findViewById(id);
        textView.setTextColor(getResources().getColor(R.color.white));
        textView.setHintTextColor(getResources().getColor(R.color.white));

        bindSearchListener();
    }
}

From source file:mroza.forms.ChooseProgramActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    this.menu = menu;
    getMenuInflater().inflate(R.menu.choose_program_menu, menu);

    //Associate programs_searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView) menu
            .findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    EditText searchPlate = (EditText) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchPlate.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchPlate.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override/*from   www  .j av  a  2 s.c  o  m*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            //On search or enter clicked
            if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_NULL) {
                if (v.getText().toString().equals("")) {
                    refreshChildTableList();
                    clearSearchField();
                    clearFilters(true);
                    enableShowAllButton(false);
                }
            }
            return false;
        }
    });

    restoreSavedFilters();
    return true;
}

From source file:edu.sfsu.csc780.chathub.ui.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DesignUtils.applyColorfulTheme(this);
    setContentView(R.layout.activity_main);
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    // Set default username is anonymous.
    mUsername = ANONYMOUS;// w  w  w . j ava 2  s.c om
    //Initialize Auth
    mAuth = FirebaseAuth.getInstance();
    mUser = mAuth.getCurrentUser();
    if (mUser == null) {
        startActivity(new Intent(this, SignInActivity.class));
        finish();
        return;
    } else {
        mUsername = mUser.getDisplayName();
        if (mUser.getPhotoUrl() != null) {
            mPhotoUrl = mUser.getPhotoUrl().toString();
        }
    }

    AudioUtil.startAudioListener(this);

    mSinchClient = Sinch.getSinchClientBuilder().context(getApplicationContext())
            .applicationKey(APIKeys.SINCH_API_KEY).applicationSecret(APIKeys.SINCH_APP_SECRET)
            .environmentHost("sandbox.sinch.com")
            .userId(UserUtil.parseUsername(mSharedPreferences.getString("username", "anonymous"))).build();
    mSinchClient.setSupportCalling(true);

    mCurrentChannel = mSharedPreferences.getString("currentChannel", "general");
    mCurrChanTextView = (TextView) findViewById(R.id.currentChannelName);
    mCurrChanTextView.setText(ChannelUtil.getChannelDisplayName(mCurrentChannel, this));

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API).build();

    // Initialize ProgressBar and RecyclerView.

    mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView);
    mLinearLayoutManager = new LinearLayoutManager(this);
    mLinearLayoutManager.setStackFromEnd(true);
    mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
    mChannelAdd = (RelativeLayout) findViewById(R.id.channelAdd);

    mToolBar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolBar);
    mToolBar.setTitleTextColor(Color.WHITE);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    mDrawerLayout.setStatusBarBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));

    mFirebaseAdapter = MessageUtil.getFirebaseAdapter(this, this, /* MessageLoadListener */
            mLinearLayoutManager, mMessageRecyclerView, mImageClickListener);
    mMessageRecyclerView.setAdapter(mFirebaseAdapter);

    mProgressBar.setVisibility(ProgressBar.INVISIBLE);

    mMessageEditText = (EditText) findViewById(R.id.messageEditText);
    mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(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 = (FloatingActionButton) findViewById(R.id.sendButton);
    mSendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Send messages on click.
            mMessageRecyclerView.scrollToPosition(0);
            ChatMessage chatMessage = new ChatMessage(mMessageEditText.getText().toString(), mUsername,
                    mPhotoUrl, mCurrentChannel);
            MessageUtil.send(chatMessage, MainActivity.this);
            mMessageEditText.setText("");
        }
    });

    mImageButton = (ImageButton) findViewById(R.id.shareImageButton);
    mImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            pickImage();
        }
    });

    mPhotoButton = (ImageButton) findViewById(R.id.cameraButton);
    mPhotoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dispatchTakePhotoIntent();
        }
    });

    mLocationButton = (ImageButton) findViewById(R.id.locationButton);
    mLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            loadMap();
        }
    });

    mChannelAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(MainActivity.this, ChannelSearchActivity.class);
            startActivityForResult(intent, REQUEST_NEW_CHANNEL);
        }
    });

    SearchView jumpSearchView = (SearchView) findViewById(R.id.jumpSearch);
    int id = jumpSearchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
    TextView textView = (TextView) jumpSearchView.findViewById(id);
    textView.setTextColor(Color.WHITE);
    textView.setHintTextColor(Color.WHITE);

    jumpSearchView.setIconified(false);
    jumpSearchView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(MainActivity.this, "Not implemented", Toast.LENGTH_SHORT).show();
        }
    });

    mNavRecyclerView = (RecyclerView) findViewById(R.id.navRecyclerView);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    mNavRecyclerView.setLayoutManager(linearLayoutManager);
    mNavRecyclerView.setAdapter(ChannelUtil.getFirebaseAdapterForUserChannelList(mChannelClickListener,
            mAuth.getCurrentUser().getDisplayName()));

    RecyclerView userListRecyclerView = (RecyclerView) findViewById(R.id.userListRecyclerView);
    LinearLayoutManager linearLayoutManager2 = new LinearLayoutManager(this);
    userListRecyclerView.setLayoutManager(linearLayoutManager2);
    userListRecyclerView.setAdapter(UserUtil.getFirebaseAdapterForUserList(mChannelClickListener));

    Button voiceCallButton = (Button) findViewById(R.id.voiceCall);
    mCallProgressTextView = (TextView) findViewById(R.id.callinprogress);

    final AudioManager audioManager = (AudioManager) getApplicationContext()
            .getSystemService(Context.AUDIO_SERVICE);
    voiceCallButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            CallClient callClient = mSinchClient.getCallClient();
            if (canCall) {
                call = callClient.callConference("General");
                call.addCallListener(new CallListener() {
                    @Override
                    public void onCallProgressing(Call call) {
                        //setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
                        audioManager.adjustStreamVolume(AudioManager.STREAM_VOICE_CALL,
                                AudioManager.ADJUST_RAISE, 10);
                        Log.d("Call", "Call progressing");
                    }

                    @Override
                    public void onCallEstablished(Call call) {
                        setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
                        mCallProgressTextView.setVisibility(View.VISIBLE);
                        Log.d("Call", "Calling now");
                    }

                    @Override
                    public void onCallEnded(Call call) {
                        setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
                        Log.d("Call", "Stopped calling");
                        mCallProgressTextView.setVisibility(View.INVISIBLE);
                    }

                    @Override
                    public void onShouldSendPushNotification(Call call, List<PushPair> list) {
                        Log.d("Call", "Push");
                    }
                });
            }
        }
    });

    Button endCallButton = (Button) findViewById(R.id.endCall);
    endCallButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (call != null) {
                call.hangup();
                call = null;
            }
        }
    });
}