当前位置: 首页>>代码示例>>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;未经允许,请勿转载。