0

I have this code that work perfect to delete an item from listview and it disappear. I want to show dialog to ask if the user want to delete an item.

public void ShowdatainlstView() {
    Boodschappenlst.clear();
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
            this,
            android.R.layout.simple_list_item_1,
            Boodschappenlst);
    lstviewProducten.setAdapter(arrayAdapter);
    lstviewProducten.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Boodschappenlst.remove(position);
            arrayAdapter.notifyDataSetChanged();
        }
    });
}
Smith Gta
  • 7
  • 8

1 Answers1

0
        new AlertDialog.Builder(this)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle("Are you sure?")
            .setMessage("do you want to delete this?")
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Log.i("Button Tapped","Yes");
                }
            })
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Log.i("Button Tapped","No");
                }
            })
            .show();
Joseph Mathew
  • 1,269
  • 15
  • 17
  • Can u tell me how i can modify my code so it only open when a item in list view is clicked. Because now with this code dialog is showing on the moment when i open my activity – Smith Gta Nov 18 '17 at 11:28