0
Besoin d'aide sérieuse avec todolist android n'importe qui pourrait aider s'il vous plaît. J'essaie de supprimer le dernier élément inséré dans la liste, il ne fonctionne pas pour certaines raisons. s'il vous plaît aider si vous pouvez voir le ci-dessous:Enlever l'article de todoList
ToDoList.java
public class ToDoList extends Activity implements OnClickListener, OnKeyListener {
Button btnRemove;
ArrayList<String> todoItems;
ArrayAdapter<String> aa;
ListView myListView ;
EditText myEditText ;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Inflate your view
setContentView(R.layout.main);
// Get references to UI widgets
myListView = (ListView)findViewById(R.id.myListView);
myEditText = (EditText)findViewById(R.id.myEditText);
// Create the ArrayList and the ArrayAdapter
todoItems = new ArrayList<String>();
aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,todoItems);
// Bind the listview to the array adapter
myListView.setAdapter(aa);
btnRemove = (Button)findViewById(R.id.btnRemove);
// Add key listener to add the new todo item
// when the middle D-pad button is pressed.
myEditText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN)
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
// Add the new todo item, and clear the input text box
todoItems.add(0, myEditText.getText().toString());
myEditText.setText("");
aa.notifyDataSetChanged();
return true;
}
return false;
}
});
}
@Override
public void onClick(View v) {
if(v == btnRemove){
if(todoItems.size() > 0){
todoItems.remove(todoItems.size() - 1);
aa.notifyDataSetChanged();
}
}
}
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
return false;
}
}