Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've solved the issue. </p> <p>1) I have used the class AlmanacSQLiteDatabaseAdapter.java used in Almanac 0.0.17 (open source project) that you can find here: <a href="http://code.google.com/p/almanac/source/browse/trunk/Almanac/src/it/almanac/AlmanacSQLiteDatabaseAdapter.java?r=56" rel="nofollow">link</a>. You can fit to your needs (in my case I'have renamed to DatabaseHelper);</p> <p>2) This is the class that uses the Helper (it is a listview that do sql rawquery reading strings in a EditText - it is an arrangement of this tutorial "coenraets.org/blog/android-samples/androidtutorial/":</p> <pre><code>public class MiaList extends Activity { protected EditText searchText; protected SQLiteDatabase db; protected Cursor cursor; protected ListAdapter ladapter; protected ListView miaList; private static final String DATABASE_NAME = "miodb.jpg"; /* L'ESTENSIONE JPG (o mp3, mov) questo perchè android ha il limite di 1 mb per i file di testo o simili nella asset, mentre NON HA limiti per i file multimediali! Nel mio caso si tratta di 4mb */ /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //qui sotto richiamo la classe DatabaseHelper DatabaseHelper dbAdapter = DatabaseHelper.getInstance(this, DATABASE_NAME); /*note di Vytek*/ // OK Dovrei usare aSQLiteDatabaseAdapter.getDatabase(); ma questo crea // problemi nella fase di OnPause quando premo Back cosi' invece non // ottengo errori // e viene fatta la normale copia del DB (13/8/2010 23.18) // db = aSQLiteDatabaseAdapter.getWritableDatabase(); // Per ovviare a questo problema controllo se e' la prima volta che // chiamo applicazione if (getFirstRun()) { db = dbAdapter.getDatabase(); setRunned(); } else { db = dbAdapter.getWritableDatabase(); } searchText = (EditText) findViewById (R.id.searchText); miaList = (ListView) findViewById (R.id.list); } private void setRunned() { // TODO Auto-generated method stub } private boolean getFirstRun() { // TODO Auto-generated method stub return false; } public void search(View view) { String text = searchText.getText().toString(); // || è l'operatore "concatena" in SQLite if (text.length()&lt;15){ cursor = db.rawQuery("SELECT *FROM miatable WHERE AAA || ' ' || BBB || ' ' || CCC LIKE ? LIMIT 30", new String[]{"%" + searchText.getText().toString() + "%"}); ladapter = new SimpleCursorAdapter( this, R.layout.mialist_list_item, cursor, new String[] {"_id", "AAA", "BBB", "CCC"}, new int[] {R.id._id, R.id.AAA, R.id.BBB, R.id.CCC}); miaList.setAdapter(ladapter); //istruzione da eseguire } else { cursor = db.rawQuery("SELECT * FROM miatable WHERE AAA || BBB LIKE ? LIMIT 30", new String[]{"%" + searchText.getText().toString().substring(6,10) + "%" + searchText.getText().toString().substring(11,15) + "%"}); ladapter = new SimpleCursorAdapter( this, R.layout.mialist_list_item, cursor, new String[] {"_id", "AAA", "BBB", "CCC"}, new int[] {R.id._id, R.id.AAA, R.id.BBB, R.id.CCC}); miaList.setAdapter(ladapter); //istruzione da eseguire } } } </code></pre> <p>Of course the SQLite DB "miodb.jpg" must be in the asset folder of eclipse's workspace.</p> <p><strong>PS</strong> <em>I have used jpg extension for the db beacause the asset folder has a 1Mb limit for db or txt or xml extension.</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload