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
|
public class CheckActivity extends ListActivity
{
/** Called when the activity is first created. */
private EditText _filterText = null;
private personAdapter _adapter = null;
private List<Person> Person;
private ListView personList;
@SuppressWarnings("unchecked")
@Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
person = new ArrayList<person> ();
person.add (new person ("Toto", "Toti"));
person.add (new person ("Tata", "Titi"));
person.add (new person ("Padre", "Papa"));
person.add (new person ("Mum", "Maman"));
person.add (new person ("Aba", "ima"));
person.add (new person ("Mickey", "Mouse"));
person.add (new person ("Mini", "Mouse"));
person.add (new person ("Testeur", "Pro"));
person.add (new person ("Developpez", "Forum"));
person.add (new person ("Voilou", "Voili"));
Collections.sort (person);
// Initialisation de la position
for (int i = 0; i < person.size (); i++)
person.get (i).setPosition (i);
_adapter = new personAdapter (this, person);
setListAdapter (_adapter);
personList = getListView ();
personList.setItemsCanFocus (false);
personList.setOnItemClickListener (new OnItemClickListener ()
{
@Override
public void onItemClick (AdapterView<?> parentView,
View selectedItemView, int position, long id)
{
CheckBox c = (CheckBox) selectedItemView
.findViewById (R.id.checkbox);
//On recupere le tag
ViewHolder view = ((ViewHolder) c.getTag ());
//On gere le check
if (!c.isChecked ())
{
person.get (view.position).setChecked (true);
}
else
{
person.get (view.position).setChecked (false);
}
//On replace la liste à la bonne position
int pos = parentView.getFirstVisiblePosition ();
personList.setSelection (pos);
}
});
}
} |
Partager