1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| public class menu extends Activity {
private ListView listContent;
private EditText et;
private ArrayList<String> array_sort= new ArrayList<String>();
int textlength=0;
private SQLiteAdapter mySQLiteAdapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dictionnaire);
listContent = (ListView)findViewById(R.id.contentlist);
et = (EditText) findViewById(R.id.villeRecherche);
/*
* Create/Open a SQLite database
* and fill with dummy content
* and close it
*/
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToWrite();
mySQLiteAdapter.deleteAll();
mySQLiteAdapter.insert("abondante");
mySQLiteAdapter.insert("abonné");
mySQLiteAdapter.insert("abonnement");
mySQLiteAdapter.insert("abonnements");
mySQLiteAdapter.insert("abonner");
mySQLiteAdapter.insert("avril");
mySQLiteAdapter.insert("bagage");
mySQLiteAdapter.insert("baisse");
mySQLiteAdapter.insert("baisser");
mySQLiteAdapter.insert("bancaire");
mySQLiteAdapter.insert("banque");
mySQLiteAdapter.insert("barbie");
mySQLiteAdapter.insert("bas");
mySQLiteAdapter.insert("bateau");
mySQLiteAdapter.close();
/*
* Open the same SQLite database
* and read all it's content.
*/
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToRead();
Cursor cursor = mySQLiteAdapter.queueAll();
startManagingCursor(cursor);
String[] from = new String[]{SQLiteAdapter.KEY_CONTENT};
int[] to = new int[]{R.id.text};
SimpleCursorAdapter cursorAdapter =
new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
listContent.setAdapter(cursorAdapter);
et.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s)
{
// Abstract Method of TextWatcher Interface.
}
public void beforeTextChanged(CharSequence s,
int start, int count, int after)
{
// Abstract Method of TextWatcher Interface.
}
public void onTextChanged(CharSequence s,
int start, int before, int count)
{
textlength = et.getText().length();
array_sort.clear();
for (int i = 0; i < from.length; i++)
{
if (textlength <= from[i].length())
{
if(et.getText().toString().equalsIgnoreCase
((String)from[i].subSequence(0,textlength)))
{
array_sort.add(from[i]);
}
}
}
listContent.setAdapter(new ArrayAdapter<String>
(menu.this,android.R.layout.simple_expandable_list_item_1, array_sort));
}
});
listContent.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
// TODO Auto-generated method stub
if (position==0 ) {
Intent deus = new Intent(getApplicationContext(), pre.class);
startActivity(deus);
}
if (position==1 ) {
Intent deus1 = new Intent(getApplicationContext(), pre.class);
startActivity(deus1);
}
}
});
}
} |
Partager