1

Hello i have a problem for my App. I develop a Online Shopping List for some friends and my family. It works finde but i would implement a new function.

I add a listview.setOnItemClickListener in my code.

And here comes my Question

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                String value = (String)adapter.getItem(position);

               }
        });

How can i set a AlertDialog, that ask the user to highline the 'value' - article?

My listView use the normal adapter, no custom adapter and fills the content with a layout ressource.

Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55
Lyan
  • 23
  • 3

1 Answers1

2

You can use the following code to redirect users to choose:

private final Context context=this;

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                context);
        alertDialogBuilder.setTitle("Please choose");
        alertDialogBuilder
                .setMessage("Please select "+value)
                .setCancelable(false)
                .setPositiveButton("Select"+value+article,new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        // if this button is clicked, close
                        // current activity
                        MainActivity.this.finish();
                    }
                })
                .setNegativeButton("No",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        // if this button is clicked, just close
                        // the dialog box and do nothing
                        dialog.cancel();
                    }
                });
        AlertDialog alertDialog = alertDialogBuilder.create();

        // show it
        alertDialog.show();
Lips_coder
  • 686
  • 1
  • 5
  • 17