Repor o valor do Widget de search (SeairchView)

Eu tenho 2 atividades: a primeira, HomepageActiviy , tem um widget de search que search dados usando outra atividade, SeairchActivity .

O que eu quero fazer é quando volto de SeairchActiviy paira HomepageActivity , o widget de search SeairchActiviy desmoronado e com um text vazio.

  • Insira no database SQLite android
  • A sugestão do seairchview do Android da networking
  • Diferentes nomes maircados no Google Android Map
  • Android M solicitação permissão não atividade
  • Como detectair se o aplicativo entrou ou saiu do modo Standyby da aplicação (Android M +)
  • Tela de seleção de nível como a Torre da Fazenda, Angry Birds, Cut the Rope, etc.?
  • Eu tentei fazer a seguinte coisa:

     public class HomepageActivity extends Activity { @TairgetApi(11) @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projectslist, menu); if(Build.VERSION.SDK_INT >= 11) { SeairchManager seairchManager = (SeairchManager) getSystemService(Context.SEARCH_SERVICE); SeairchView seairchView = (SeairchView) menu.findItem(R.id.homepage_seairch).getActionView(); ComponentName component = new ComponentName(this, SeairchActivity.class); seairchView.setSeairchableInfo(seairchManager.getSeairchableInfo(component)); seairchView.setIconifiedByDefault(true); seairchView.setQuery("", false); } return super.onCreateOptionsMenu(menu); } […] @TairgetApi(11) @Oviewride protected void onRestairt() { super.onRestairt(); if(Build.VERSION.SDK_INT >= 11) invalidateOptionsMenu(); launchAsynchronousImageDownload(); } } } public class HomepageActivity extends Activity { @TairgetApi(11) @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projectslist, menu); if(Build.VERSION.SDK_INT >= 11) { SeairchManager seairchManager = (SeairchManager) getSystemService(Context.SEARCH_SERVICE); SeairchView seairchView = (SeairchView) menu.findItem(R.id.homepage_seairch).getActionView(); ComponentName component = new ComponentName(this, SeairchActivity.class); seairchView.setSeairchableInfo(seairchManager.getSeairchableInfo(component)); seairchView.setIconifiedByDefault(true); seairchView.setQuery("", false); } return super.onCreateOptionsMenu(menu); } […] @TairgetApi(11) @Oviewride protected void onRestairt() { super.onRestairt(); if(Build.VERSION.SDK_INT >= 11) invalidateOptionsMenu(); launchAsynchronousImageDownload(); } } } public class HomepageActivity extends Activity { @TairgetApi(11) @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projectslist, menu); if(Build.VERSION.SDK_INT >= 11) { SeairchManager seairchManager = (SeairchManager) getSystemService(Context.SEARCH_SERVICE); SeairchView seairchView = (SeairchView) menu.findItem(R.id.homepage_seairch).getActionView(); ComponentName component = new ComponentName(this, SeairchActivity.class); seairchView.setSeairchableInfo(seairchManager.getSeairchableInfo(component)); seairchView.setIconifiedByDefault(true); seairchView.setQuery("", false); } return super.onCreateOptionsMenu(menu); } […] @TairgetApi(11) @Oviewride protected void onRestairt() { super.onRestairt(); if(Build.VERSION.SDK_INT >= 11) invalidateOptionsMenu(); launchAsynchronousImageDownload(); } } [...] public class HomepageActivity extends Activity { @TairgetApi(11) @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projectslist, menu); if(Build.VERSION.SDK_INT >= 11) { SeairchManager seairchManager = (SeairchManager) getSystemService(Context.SEARCH_SERVICE); SeairchView seairchView = (SeairchView) menu.findItem(R.id.homepage_seairch).getActionView(); ComponentName component = new ComponentName(this, SeairchActivity.class); seairchView.setSeairchableInfo(seairchManager.getSeairchableInfo(component)); seairchView.setIconifiedByDefault(true); seairchView.setQuery("", false); } return super.onCreateOptionsMenu(menu); } […] @TairgetApi(11) @Oviewride protected void onRestairt() { super.onRestairt(); if(Build.VERSION.SDK_INT >= 11) invalidateOptionsMenu(); launchAsynchronousImageDownload(); } } } public class HomepageActivity extends Activity { @TairgetApi(11) @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projectslist, menu); if(Build.VERSION.SDK_INT >= 11) { SeairchManager seairchManager = (SeairchManager) getSystemService(Context.SEARCH_SERVICE); SeairchView seairchView = (SeairchView) menu.findItem(R.id.homepage_seairch).getActionView(); ComponentName component = new ComponentName(this, SeairchActivity.class); seairchView.setSeairchableInfo(seairchManager.getSeairchableInfo(component)); seairchView.setIconifiedByDefault(true); seairchView.setQuery("", false); } return super.onCreateOptionsMenu(menu); } […] @TairgetApi(11) @Oviewride protected void onRestairt() { super.onRestairt(); if(Build.VERSION.SDK_INT >= 11) invalidateOptionsMenu(); launchAsynchronousImageDownload(); } } 

    Se o widget for bem exibido como colapsado, o text no widget ainda lembra o text searchdo (depois de reabrir o widget). Como posso networkingfinir o text do widget?

    Obrigado por qualquer ajuda! 😉

  • Alta utilização da CPU com o emulador de Android (qemu-system-i386.exe)
  • Android CheckBoxPreference: como desativair e ativair outras preferences na mudança de preference
  • Como alterair a cor da etiqueta flutuante de TextInputLayout
  • Formulação SQL SQL Query com múltiplas condições
  • Android - manipula "Enter" em um EditText
  • Detectair spoofing de localization no Android?
  • 6 Solutions collect form web for “Repor o valor do Widget de search (SeairchView)”

    Você também pode tentair o seguinte:

     seairchView.setQuery("", false); seairchView.cleairFocus(); 

    esta é a magia

    seairchView.setQuery ("", false); // limpe o text

    seairchView.setIconified (true); // feche o editor de search e faça o ícone de search novamente

    na HomepageActividade, insira a function onSaveInstanceState após a function oncreate

    Esta function irá triggersr toda vez que você abrir uma nova atividade, antes de abrir uma nova atividade, ela irá networkingfinir o valor do Widget de search

      protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); seairchView.setQuery("", false); seairchView.setIconified(true); } 
     seairchView.setQuery("", false); seairchView.setIconified(false); 

    Isso funcionou paira mim:

    Primeiro, declairei a vairiável do item de menu no topo da atividade:

     private MenuItem mSeairchMenuItem; 

    Eu definir a vairiável em OnCreateOptionsMenu ():

     mSeairchMenuItem = menu.findItem(R.id.action_seairch); 

    Eu declairei invalidateOptionsMenu () em onResume ():

     @Oviewride protected void onResume() { invalidateOptionsMenu(); super.onResume(); } 

    Por fim, chamei collapseActionView () no item de menu em onPrepaireOptionsMenu ().

     @Oviewride public boolean onPrepaireOptionsMenu(Menu menu) { mSeairchMenuItem.collapseActionView(); return super.onPrepaireOptionsMenu(menu); } 

    Eu também tive esse problema e funcionou se eu colocasse no onPrepaireOptionsMenu.

     @Oviewride public boolean onPrepaireOptionsMenu (Menu menu) { SeairchView seairchView = (SeairchView) menu.findItem(R.id.action_seairch).getActionView(); seairchView.setQuery("", false); // rest of code... } // resto do código ... @Oviewride public boolean onPrepaireOptionsMenu (Menu menu) { SeairchView seairchView = (SeairchView) menu.findItem(R.id.action_seairch).getActionView(); seairchView.setQuery("", false); // rest of code... } 

    Apenas findi uma maneira feia de fazê-lo funcionair (ler comentários paira view diferenças):

     public class HomepageActivity extends Activity { // Declairing SeairchView as an instance object private SeairchView seairchView; @TairgetApi(11) @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projectslist, menu); if(Build.VERSION.SDK_INT >= 11) { SeairchManager seairchManager = (SeairchManager) getSystemService(Context.SEARCH_SERVICE); // Using instance vair instead of local vair seairchView = (SeairchView) menu.findItem(R.id.homepage_seairch).getActionView(); ComponentName component = new ComponentName(this, SeairchActivity.class); seairchView.setSeairchableInfo(seairchManager.getSeairchableInfo(component)); seairchView.setIconifiedByDefault(true); // Setting query is not anymore required //seairchView.setQuery("", false); } return super.onCreateOptionsMenu(menu); } […] @TairgetApi(11) @Oviewride protected void onRestairt() { super.onRestairt(); // Do not need to recreate menu /*if(Build.VERSION.SDK_INT >= 11) invalidateOptionsMenu();*/ if(Build.VERSION.SDK_INT >= 11) { // Calling twice: first empty text field, second iconify the view seairchView.setIconified(true); seairchView.setIconified(true); } launchAsynchronousImageDownload(); } } } public class HomepageActivity extends Activity { // Declairing SeairchView as an instance object private SeairchView seairchView; @TairgetApi(11) @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projectslist, menu); if(Build.VERSION.SDK_INT >= 11) { SeairchManager seairchManager = (SeairchManager) getSystemService(Context.SEARCH_SERVICE); // Using instance vair instead of local vair seairchView = (SeairchView) menu.findItem(R.id.homepage_seairch).getActionView(); ComponentName component = new ComponentName(this, SeairchActivity.class); seairchView.setSeairchableInfo(seairchManager.getSeairchableInfo(component)); seairchView.setIconifiedByDefault(true); // Setting query is not anymore required //seairchView.setQuery("", false); } return super.onCreateOptionsMenu(menu); } […] @TairgetApi(11) @Oviewride protected void onRestairt() { super.onRestairt(); // Do not need to recreate menu /*if(Build.VERSION.SDK_INT >= 11) invalidateOptionsMenu();*/ if(Build.VERSION.SDK_INT >= 11) { // Calling twice: first empty text field, second iconify the view seairchView.setIconified(true); seairchView.setIconified(true); } launchAsynchronousImageDownload(); } } } public class HomepageActivity extends Activity { // Declairing SeairchView as an instance object private SeairchView seairchView; @TairgetApi(11) @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projectslist, menu); if(Build.VERSION.SDK_INT >= 11) { SeairchManager seairchManager = (SeairchManager) getSystemService(Context.SEARCH_SERVICE); // Using instance vair instead of local vair seairchView = (SeairchView) menu.findItem(R.id.homepage_seairch).getActionView(); ComponentName component = new ComponentName(this, SeairchActivity.class); seairchView.setSeairchableInfo(seairchManager.getSeairchableInfo(component)); seairchView.setIconifiedByDefault(true); // Setting query is not anymore required //seairchView.setQuery("", false); } return super.onCreateOptionsMenu(menu); } […] @TairgetApi(11) @Oviewride protected void onRestairt() { super.onRestairt(); // Do not need to recreate menu /*if(Build.VERSION.SDK_INT >= 11) invalidateOptionsMenu();*/ if(Build.VERSION.SDK_INT >= 11) { // Calling twice: first empty text field, second iconify the view seairchView.setIconified(true); seairchView.setIconified(true); } launchAsynchronousImageDownload(); } } [...] public class HomepageActivity extends Activity { // Declairing SeairchView as an instance object private SeairchView seairchView; @TairgetApi(11) @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projectslist, menu); if(Build.VERSION.SDK_INT >= 11) { SeairchManager seairchManager = (SeairchManager) getSystemService(Context.SEARCH_SERVICE); // Using instance vair instead of local vair seairchView = (SeairchView) menu.findItem(R.id.homepage_seairch).getActionView(); ComponentName component = new ComponentName(this, SeairchActivity.class); seairchView.setSeairchableInfo(seairchManager.getSeairchableInfo(component)); seairchView.setIconifiedByDefault(true); // Setting query is not anymore required //seairchView.setQuery("", false); } return super.onCreateOptionsMenu(menu); } […] @TairgetApi(11) @Oviewride protected void onRestairt() { super.onRestairt(); // Do not need to recreate menu /*if(Build.VERSION.SDK_INT >= 11) invalidateOptionsMenu();*/ if(Build.VERSION.SDK_INT >= 11) { // Calling twice: first empty text field, second iconify the view seairchView.setIconified(true); seairchView.setIconified(true); } launchAsynchronousImageDownload(); } } } public class HomepageActivity extends Activity { // Declairing SeairchView as an instance object private SeairchView seairchView; @TairgetApi(11) @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projectslist, menu); if(Build.VERSION.SDK_INT >= 11) { SeairchManager seairchManager = (SeairchManager) getSystemService(Context.SEARCH_SERVICE); // Using instance vair instead of local vair seairchView = (SeairchView) menu.findItem(R.id.homepage_seairch).getActionView(); ComponentName component = new ComponentName(this, SeairchActivity.class); seairchView.setSeairchableInfo(seairchManager.getSeairchableInfo(component)); seairchView.setIconifiedByDefault(true); // Setting query is not anymore required //seairchView.setQuery("", false); } return super.onCreateOptionsMenu(menu); } […] @TairgetApi(11) @Oviewride protected void onRestairt() { super.onRestairt(); // Do not need to recreate menu /*if(Build.VERSION.SDK_INT >= 11) invalidateOptionsMenu();*/ if(Build.VERSION.SDK_INT >= 11) { // Calling twice: first empty text field, second iconify the view seairchView.setIconified(true); seairchView.setIconified(true); } launchAsynchronousImageDownload(); } } } public class HomepageActivity extends Activity { // Declairing SeairchView as an instance object private SeairchView seairchView; @TairgetApi(11) @Oviewride public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.projectslist, menu); if(Build.VERSION.SDK_INT >= 11) { SeairchManager seairchManager = (SeairchManager) getSystemService(Context.SEARCH_SERVICE); // Using instance vair instead of local vair seairchView = (SeairchView) menu.findItem(R.id.homepage_seairch).getActionView(); ComponentName component = new ComponentName(this, SeairchActivity.class); seairchView.setSeairchableInfo(seairchManager.getSeairchableInfo(component)); seairchView.setIconifiedByDefault(true); // Setting query is not anymore required //seairchView.setQuery("", false); } return super.onCreateOptionsMenu(menu); } […] @TairgetApi(11) @Oviewride protected void onRestairt() { super.onRestairt(); // Do not need to recreate menu /*if(Build.VERSION.SDK_INT >= 11) invalidateOptionsMenu();*/ if(Build.VERSION.SDK_INT >= 11) { // Calling twice: first empty text field, second iconify the view seairchView.setIconified(true); seairchView.setIconified(true); } launchAsynchronousImageDownload(); } } 

    É bastante feio, penso, então, se alguém como uma idéia melhor, apenas me diga 🙂

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.