Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/12/2015, 16:01
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Autocompletado con consulta a Sqlite

Hola, por favor tengo este código que funciona bien. Se trata de un input con búsqueda de datos:
Código Java:
Ver original
  1. static final String[] countries = new String[] { "Afghastan", "Albanie",
  2.             "Tunisie", "Ukrania", "Tchekozlovakia" };


Pero lo que quisiera es que me hiciera un SELECT a la base de datos Sqlite para que conforme voy escribiendo en el campo de texto me vaya saliendo debajo una lista de los resultados obtenidos.



ElecBuscarCliente.java
Código Java:
Ver original
  1. import android.app.ListActivity;
  2. import android.os.Bundle;
  3. import android.text.Editable;
  4. import android.text.TextWatcher;
  5. import android.view.View;
  6. import android.widget.AdapterView;
  7. import android.widget.ArrayAdapter;
  8. import android.widget.EditText;
  9. import android.widget.ListView;
  10. import android.widget.TextView;
  11. import android.widget.Toast;
  12.  
  13.  
  14. /**
  15.  * Created by Ivan on 09/11/2015.
  16.  */
  17.  
  18. public class ElecBuscarCliente extends ListActivity {
  19.     private EditText txtInput;
  20.  
  21.  
  22.     static final String[] countries = new String[] { "Afghastan", "Albanie",
  23.             "Tunisie", "Ukrania", "Tchekozlovakia" };
  24.  
  25.     /** Called when the activity is first created. */
  26.     @Override
  27.     public void onCreate(Bundle savedInstanceState) {
  28.         super.onCreate(savedInstanceState);
  29.         setContentView(R.layout.buscar_clientes);
  30.         final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
  31.                 android.R.layout.simple_list_item_1, countries);
  32.         setListAdapter(adapter);
  33.         txtInput = (EditText) findViewById(R.id.state_name);
  34.         txtInput.addTextChangedListener(new TextWatcher() {
  35.             public void afterTextChanged(Editable theWatchedText) {
  36.  
  37.             }
  38.  
  39.             public void beforeTextChanged(CharSequence arg0, int arg1,
  40.                                           int arg2, int arg3) {
  41. // Toast.makeText(getApplicationContext(), "BTC " + arg0,
  42. // 1).show();
  43.             }
  44.  
  45.             public void onTextChanged(CharSequence arg0, int start, int count,
  46.                                       int after) {
  47.                 adapter.getFilter().filter(arg0.toString());
  48.  
  49. // Toast.makeText(getApplicationContext(), "OTC " + arg0,
  50. // 1).show();
  51.             }
  52.         }); // addTextChangedListener
  53.         ListView lv = getListView();
  54.         lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  55.  
  56.             public void onItemClick(AdapterView<?> parent, View view,
  57.                                     int position, long id) {
  58.                 Toast.makeText(getApplicationContext(),
  59.                         ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
  60.  
  61.             }
  62.  
  63.         });
  64. /* AutoCompleteTextView textView=(AutoCompleteTextView)findViewById(R.id.autocomplete_country);
  65. ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, R.layout.list_item, countries);
  66. textView.setAdapter(adapter);*/
  67.     }
  68. }

buscar_clientes.xml
Código Java:
Ver original
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3.  
  4. <LinearLayout
  5.     xmlns:android="http://schemas.android.com/apk/res/android"
  6.     android:orientation="vertical"
  7.     android:layout_width="match_parent"
  8.     android:layout_height="match_parent">
  9.     <TableRow
  10.         android:layout_width="300dp"
  11.         android:layout_height="wrap_content"
  12.         android:layout_gravity="center_horizontal"
  13.         android:weightSum="1">
  14.  
  15.  
  16.         <!-- Note: android:inputType is not supported in Android 1.5 -->
  17.         <EditText
  18.             android:layout_width="fill_parent"
  19.             android:inputType="textNoSuggestions"
  20.             android:layout_height="wrap_content"
  21.             android:completionThreshold="1"
  22.             android:id="@+id/state_name" />
  23.  
  24.     </TableRow>
  25.  
  26.     <ScrollView
  27.         android:layout_width="match_parent"
  28.         android:layout_height="match_parent">
  29.  
  30.         <FrameLayout
  31.             android:layout_width="match_parent"
  32.             android:layout_height="wrap_content"
  33.             android:layout_weight="1">
  34.  
  35.             <ListView
  36.                 android:id="@+id/android:list"
  37.                 android:layout_width="match_parent"
  38.                 android:layout_height="match_parent"
  39.                 android:drawSelectorOnTop="false"
  40.                 android:layout_marginLeft="7dp"
  41.                 android:layout_marginRight="7dp" />
  42.  
  43.         </FrameLayout>
  44.     </ScrollView>
  45.  
  46. </LinearLayout>

Gracias