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();
        }
    });
}
1
  • Look this Commented Nov 17, 2017 at 20:53

1 Answer 1

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();
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.