Mark023
Mark023

Reputation: 105

launch custom dialog for click of a position in OnClickListener of Listview

I am developing an Android app to display children names. I populate the names in the listview.

My requirement is that when a child arrives to the school, I gray him out in the list and highlight the next child name in the list. This I have done. The pending thing is when I click on the child name who already arrived(greyed out), I need to launch an alert dialog. How do I do this in onItemClick()

Upvotes: 0

Views: 140

Answers (1)

MalcolmMcFly
MalcolmMcFly

Reputation: 402

Maybe try something like this in your onItemClick():

    public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            new AlertDialog.Builder(context)
             .setTitle("Sign In")
             .setMessage("Do you want to sign in this child?")
             .setPositiveButton("yes", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) { 
              // sign in child 
             }})
             .setNegativeButton("no", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) { 
              // do nothing 
             }})
             .show();
            }

Upvotes: 1

Related Questions