Skip to content

Commit

Permalink
[ADD] Implementar busqueda en antivity recepciones
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-teruel committed Feb 16, 2015
1 parent c8622b8 commit a296d42
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<activity
android:name=".Recepciones"
android:label="@string/title_activity_recepciones" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<activity
android:name=".MovArticuloSerie"
Expand Down
52 changes: 51 additions & 1 deletion app/src/main/java/es/incaser/apps/stockcontrol/Recepciones.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package es.incaser.apps.stockcontrol;

import android.app.SearchManager;
import android.app.SearchableInfo;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
Expand All @@ -13,13 +15,18 @@
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

public class Recepciones extends ActionBarActivity {

public class Recepciones extends ActionBarActivity implements SearchView.OnQueryTextListener{
ListView lvMovimientoStock;
MovStockAdapter movStockAdapter;
DbAdapter dbAdapter;
SearchView searchView;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -45,9 +52,39 @@ public void linkListViewMovimientoStock(){
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_recepciones, menu);
searchView = (SearchView) menu.findItem(R.id.reception_search).getActionView();
setupSearchView();
return true;
}

private void setupSearchView() {


//searchView.setIconifiedByDefault(true);

SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
if (searchManager != null) {
List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();

// Try to use the "applications" global search provider
SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
for (SearchableInfo inf : searchables) {
if (inf.getSuggestAuthority() != null
&& inf.getSuggestAuthority().startsWith("applications")) {
info = inf;
}
}
searchView.setSearchableInfo(info);
}

searchView.setOnQueryTextListener(this);
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
return false;
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
Expand All @@ -62,6 +99,19 @@ public boolean onOptionsItemSelected(MenuItem item) {

return super.onOptionsItemSelected(item);
}

@Override
public boolean onQueryTextSubmit(String query) {
//Toast.makeText(this, query, Toast.LENGTH_SHORT).show();
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
//Toast.makeText(this, newText, Toast.LENGTH_SHORT).show();
return false;
}

public class MovStockAdapter extends BaseAdapter implements View.OnClickListener{
Context context;
Cursor cursor;
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/menu/menu_recepciones.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
tools:context="es.incaser.apps.stockcontrol.Recepciones">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
<item
android:id="@+id/reception_search"
app:showAsAction="always"
android:title="Search"
android:icon="@drawable/ic_action_search"
app:actionViewClass="android.widget.SearchView"/>

</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@
<string name="status_sync_sync_saica">SINCRONIZADO CON SAICA</string>
<string name="status_sync_para_crear">PARA CREAR</string>
<string name="status_sync_not_insql">NO EN SQL</string>
<string name="app_label">Stock Control</string>
<string name="search_hint">Buscar...</string>

</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/searchable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_label"
android:hint="@string/search_hint" >
</searchable>

0 comments on commit a296d42

Please sign in to comment.