I've assembled a list in an android application which is a simple list using SimpleAdapter
.
What I need now is to delete the item from the list, but I do not know how I would do it because I could not get the position of the button clicked.
Follow the code:
public class MostrarTodasTarefas extends AppCompatActivity {
ListView list = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mostrartodastarefas);
String[] de = { "url", "status", "lastexecute", "btnExcluir" };
int[] para = { R.id.lblURL, R.id.lblStatus, R.id.lblLastExecute, R.id.btnExcluir};
SimpleAdapter adapter = new SimpleAdapter(this, convertToMap(),
R.layout.layout_listaurls, de, para);
list = (ListView) findViewById(R.id.listTarefas);
list.setAdapter(adapter);
adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data, String textRepresentation) {
if (view.getId() == R.id.btnExcluir) {
Button b = (Button) view;
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Excluir(v);
}
});
return true;
}
return false;
}
}
);
}
public void Excluir(View view){
EventBus.getDefault().post(new MessageEvent("Excluido"));
}
}
It creates ListView
and Button
's.
Where I call Excluir(v)
works, it executes this click on all the buttons in the list.
What I can not do is take the position to do the deletion, what do I need to do?