Does anybody knows how to set android search dialog hint dynamically? T have try to do something like:
Thanks Mister Murakami for the idea, i have implemented the same concept to perform toggle search and as per my view its not a hack but its beauty of OOPs. Below program having a toggle icon in the action bar to switch between search hint.
RestaurantListingActivity.java
public class RestaurantListingActivity extends BaseMainActivity implements
TabListener {
private boolean isRestaurantSearch = true;
private SearchManager searchManager;
private SearchView searchView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar aBar = getActionBar();
aBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
aBar.addTab(aBar.newTab().setText("Place Order").setTabListener(this));
aBar.addTab(aBar.newTab().setText("My Account").setTabListener(this));
aBar.addTab(aBar.newTab().setText("Favorite").setTabListener(this));
aBar.addTab(aBar.newTab().setText("Vendor Portal").setTabListener(this));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.restaturant_listing_menu, menu);
searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
searchView = (SearchView) menu.findItem(R.id.rlm_search)
.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(new ComponentName(this,
RestaurantListingActivity.class)));
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.rlm_toggle:
isRestaurantSearch = !isRestaurantSearch;
if (isRestaurantSearch)
searchView.setSearchableInfo(searchManager
.getSearchableInfo(new ComponentName(this,
RestaurantListingActivity.class)));
else
searchView.setSearchableInfo(searchManager
.getSearchableInfo(new ComponentName(this,
RestaurantFoodSwitcherActivity.class)));
break;
case R.id.rlm_change_loc:
break;
case R.id.rlm_filter_search:
break;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void setScreenData(Object screenData, int event, long time) {
// TODO Auto-generated method stub
}
@Override
public Activity getMyActivityReference() {
// TODO Auto-generated method stub
return null;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
-
-
-
-
searchablerestra.xml inside res>xml
RestaurantFoodSwitcherActivity.java
public class RestaurantFoodSwitcherActivity extends RestaurantListingActivity {
}
searchablefood.xml
manifest.xml