本文整理汇总了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);
}
}
示例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;
}