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
|
import java.io.IOException;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.database.SQLException;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ListView;
public class Main extends ListActivity implements View.OnClickListener {
private static final String TAG = "montag";
private Personne[] lv_arr = {};
private ArrayAdapter<Personne> arrayAD;
private AutoCompleteTextView filterText;
private ProgressDialog mProgressDiag;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
filterText = (AutoCompleteTextView) findViewById(R.id.mon_filtre);
filterText.addTextChangedListener(filterTextWatcher);
new QueryTask().execute();
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
AlertDialog.Builder adb=new AlertDialog.Builder(Main.this);
adb.setTitle("Information sur la personne");
adb.setMessage("Information sur : \n"+l.getItemAtPosition(position));
adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
} });
adb.setIcon(R.drawable.info);
adb.show();
}
private class QueryTask extends AsyncTask<Void, Void, ArrayList<Personne>> {
@Override
protected void onPreExecute () {
mProgressDiag = ProgressDialog.show(Main.this, "", "Chargement en cours...", true);
}
@Override
protected ArrayList<Personne> doInBackground(Void... params) {
DataBaseHelper dbhelp = new DataBaseHelper(this);
try {
dbhelp.createDataBase();
} catch (IOException e) {
Log.e(TAG, "unable to create db");
}
try {
dbhelp.openDatabase();
}catch (SQLException sqle){
throw sqle;
}
ArrayList<Personne> listPersonne = new ArrayList<Personne>();
listPersonne = dbhelp.getAllPersonne();
dbhelp.close();
return listPersonne;
}
@Override
protected void onPostExecute(ArrayList<Personne> listPers) {
mProgressDiag.dismiss();
lv_arr = (Personne[])listPers.toArray(new Personne[0]);
arrayAD = new ArrayAdapter<Personne>(this, R.layout.affichage, lv_arr);
setListAdapter(arrayAD);
}
}
private TextWatcher filterTextWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
arrayAD.getFilter().filter(s);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
};
@Override
protected void onDestroy() {
super.onDestroy();
Log.e(TAG, "onDestroy() called");
filterText.removeTextChangedListener(filterTextWatcher);
}
@Override
public void onClick(View arg0) {
}
} |
Partager