当前位置: 首页>>代码示例>>Java>>正文


Java SearchView.setOnQueryTextFocusChangeListener方法代码示例

本文整理汇总了Java中android.widget.SearchView.setOnQueryTextFocusChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java SearchView.setOnQueryTextFocusChangeListener方法的具体用法?Java SearchView.setOnQueryTextFocusChangeListener怎么用?Java SearchView.setOnQueryTextFocusChangeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.SearchView的用法示例。


在下文中一共展示了SearchView.setOnQueryTextFocusChangeListener方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureSearchWidget

import android.widget.SearchView; //导入方法依赖的package包/类
@Override
public void configureSearchWidget(
    Activity activity, MenuItem menuItem, final TrackController trackController) {
  SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
  SearchView searchView = (SearchView) menuItem.getActionView();
  searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
  searchView.setQueryRefinementEnabled(true);
  searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
    
      @Override
    public void onFocusChange(View v, boolean hasFocus) {
        // Hide and show trackController when search widget has focus/no focus
        if (trackController != null) {
          if (hasFocus) {
            trackController.hide();
          } else {
            trackController.show();
          }
        }        
    }
  });
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:23,代码来源:Api11Adapter.java

示例2: onCreateOptionsMenu

import android.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	getMenuInflater().inflate(R.menu.activity_main, menu);

       // Associate searchable configuration with the SearchView
       SearchManager searchManager =
               (SearchManager) getSystemService(Context.SEARCH_SERVICE);
       searchMenuItem = menu.findItem(R.id.search);
       final SearchView searchView =
               (SearchView) searchMenuItem.getActionView();
       searchView.setSearchableInfo(
               searchManager.getSearchableInfo(getComponentName()));
       searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
           @Override
           public void onFocusChange(View view, boolean queryTextFocused) {
               if(!queryTextFocused) {
                   searchMenuItem.collapseActionView();
                   searchView.setQuery("", false);
               }
           }
       });

	return true;
}
 
开发者ID:danielebufarini,项目名称:Reminders,代码行数:25,代码来源:Reminders.java

示例3: onCreateOptionsMenu

import android.widget.SearchView; //导入方法依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    inflater.inflate(R.menu.vk_search_menu, menu);
    MenuItem menuItem = menu.findItem(R.id.vk_search);
    menuItem.setOnActionExpandListener(this);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
    searchView.setOnQueryTextListener(this);
    searchView.setOnQueryTextFocusChangeListener(this);
    searchView.setQuery(mSearchText, false);
    searchView.setIconifiedByDefault(false);
}
 
开发者ID:DmitriyG1,项目名称:vk-music-player-android,代码行数:14,代码来源:VKSearchFragment.java

示例4: onCreateOptionsMenu

import android.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_homepage, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) (menu.findItem(R.id.search)).getActionView();

    // Get diet preference
    //final String diet;
    if (getIntent().getExtras() != null) {
        diet = getIntent().getExtras().getString("DIET");
    } else {
        diet = "";
    }

    // Handle query
    if (searchView != null) {

        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
        String queryHint = "Search recipes...";
        searchView.setQueryHint(queryHint);

        searchView.setOnQueryTextFocusChangeListener(new SearchView.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                hideKeyboard(v);
            }
        });
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                Intent loadSearchIntent = new Intent(HomepageActivity.this, LoadResultsActivity.class);

                query = searchView.getQuery().toString();
                query = encodeQuery(query);
                String emptyString = "";
                if (diet != null && !diet.equals(emptyString)) {
                    query = "&q=" + diet + "+" + query;
                } else {
                    query = "&q=" + query;
                }

                loadSearchIntent.putExtra("DIET", diet);
                loadSearchIntent.putExtra("QUERY", query);
                loadSearchIntent.putExtra("USERNAME",username);
                loadSearchIntent.putExtra("JSON",json);
                loadSearchIntent.putExtra("NAME",name);
                loadSearchIntent.putExtra("FLAG","user");
                startActivity(loadSearchIntent);
                return true;
            }

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

    }


    return true;
}
 
开发者ID:harrij15,项目名称:SquareMeals,代码行数:66,代码来源:HomepageActivity.java

示例5: onCreateOptionsMenu

import android.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_homepage, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) (menu.findItem(R.id.search)).getActionView();

    // Get diet preference
    //final String diet;
    if (getIntent().getExtras() != null) {
        diet = getIntent().getExtras().getString("DIET");
    } else {
        diet = "";
    }

    // Handle query
    if (searchView != null) {

        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
        String queryHint = "Search recipes...";
        searchView.setQueryHint(queryHint);

        searchView.setOnQueryTextFocusChangeListener(new SearchView.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                hideKeyboard(v);
            }
        });
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                Intent loadSearchIntent = new Intent(HomepageGuestActivity.this, LoadResultsActivity.class);

                query = searchView.getQuery().toString();
                query = encodeQuery(query);
                String emptyString = "";
                if (diet != null && !diet.equals(emptyString)) {
                    query = "&q=" + diet + "+" + query;
                } else {
                    query = "&q=" + query;
                }

                loadSearchIntent.putExtra("DIET", diet);
                loadSearchIntent.putExtra("QUERY", query);
                loadSearchIntent.putExtra("USERNAME",username);
                loadSearchIntent.putExtra("JSON",json);
                loadSearchIntent.putExtra("NAME",name);
                loadSearchIntent.putExtra("FLAG","guest");
                startActivity(loadSearchIntent);
                return true;
            }

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

    }


    return true;
}
 
开发者ID:harrij15,项目名称:SquareMeals,代码行数:66,代码来源:HomepageGuestActivity.java

示例6: onCreateOptionsMenu

import android.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
       MenuInflater inflater = getMenuInflater();
       inflater.inflate(R.menu.main_menu, menu);
       
       
       final MenuItem searchMenuItem = menu.findItem(R.id.search);
       final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
       
       if(userid.contentEquals("0") || !getString(R.string.subforum_id).contentEquals("0")) {
       	searchView.setVisibility(View.GONE);
       } else {
       	if(ForegroundColorSetter.getForegroundDark(background)) {
       		searchMenuItem.setIcon(R.drawable.ic_action_search_dark);
       	}
       }

       searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
           public void onFocusChange(View view, boolean queryTextFocused) {
               if(!queryTextFocused) {
                   searchMenuItem.collapseActionView();
                   searchView.setQuery("", false);
               }
           }
       });
       
       searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

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

		public boolean onQueryTextSubmit(String query) {
			
			if(getActionBar() != null) {
				getActionBar().setSubtitle(baseSubtitle);
			}
			
			searchMenuItem.collapseActionView();
               searchView.setQuery("", false);
			
			Bundle bundle = new Bundle();
			bundle.putString("subforum_name",(String) "Search - " + query);
			bundle.putString("subforum_id",(String) "search");
			bundle.putString("query",(String) query);
			bundle.putString("background",(String) background);
			bundle.putString("icon",(String) "n/a");
			bundle.putString("inTab",(String) "N");
			
			loadForum(bundle,"SEARCH_QUERY",false);

			return false;
		}
       	
       });

       return true;
   }
 
开发者ID:abartmatozu,项目名称:forum-fiend-osp,代码行数:60,代码来源:Discussions_Main.java


注:本文中的android.widget.SearchView.setOnQueryTextFocusChangeListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。