當前位置: 首頁>>代碼示例>>Java>>正文


Java SearchView.OnQueryTextListener方法代碼示例

本文整理匯總了Java中android.widget.SearchView.OnQueryTextListener方法的典型用法代碼示例。如果您正苦於以下問題:Java SearchView.OnQueryTextListener方法的具體用法?Java SearchView.OnQueryTextListener怎麽用?Java SearchView.OnQueryTextListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.SearchView的用法示例。


在下文中一共展示了SearchView.OnQueryTextListener方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setOnQueryTextListener

import android.widget.SearchView; //導入方法依賴的package包/類
/**
 * Sets a listener for user actions within the SearchView.
 *
 * @param listener the listener object that receives callbacks when the user performs
 *                 actions in the SearchView such as clicking on buttons or typing a query.
 */
public void setOnQueryTextListener(@NonNull final SearchView.OnQueryTextListener listener) {
    if (searchView != null) {
        searchView.setOnQueryTextListener(listener);
    } else if (supportView != null) {
        supportView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
            @Override public boolean onQueryTextSubmit(String query) {
                return listener.onQueryTextSubmit(query);
            }

            @Override public boolean onQueryTextChange(String newText) {
                return listener.onQueryTextChange(newText);
            }
        });
    } else {
        throw new IllegalStateException(ERROR_NO_SEARCHVIEW);
    }
}
 
開發者ID:algolia,項目名稱:instantsearch-android,代碼行數:24,代碼來源:SearchViewFacade.java

示例2: onCreateOptionsMenu

import android.widget.SearchView; //導入方法依賴的package包/類
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	getMenuInflater().inflate(R.menu.main, menu);
	
	
	SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
       SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
               .getActionView();
       if (null != searchView) {
           searchView.setSearchableInfo(searchManager
                   .getSearchableInfo(getComponentName()));
           searchView.setIconifiedByDefault(true);
           
       }

       SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
           public boolean onQueryTextChange(String newText) {
               // this is your adapter that will be filtered
           	
           	//cardArrayAdapter.getFilter().filter(newText.toString());
           	
           //	Toast.makeText(getApplicationContext(),newText, Toast.LENGTH_SHORT).show();
               return true;
           }

           public boolean onQueryTextSubmit(String query) {
               //Here u can get the value "query" which is entered in the search box.
           	//Toast.makeText(getApplicationContext(),query, Toast.LENGTH_SHORT).show();
           	 String address = query;
	            address = address.replace(' ', '+');
	            Log.d("kkk",address);

	            // Create Intent object for starting Google Maps application
	            /*Intent geoIntent = new Intent(
	                    android.content.Intent.ACTION_VIEW, Uri
	                    .parse("geo:0,0?q=" + address));*/
	            Uri gmmIntentUri = Uri.parse("google.navigation:q="+address);
	            Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
	            mapIntent.setPackage("com.google.android.apps.maps");
	            startActivity(mapIntent);
           	
           	return true;
           		
           }
       };
       searchView.setOnQueryTextListener(queryTextListener);

   	
   	
   	
       
	
	
	
	
	return true;
	
	
}
 
開發者ID:ITheBK,項目名稱:TripBookAndroid,代碼行數:60,代碼來源:MainActivity.java


注:本文中的android.widget.SearchView.OnQueryTextListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。