title: Enable/disable dialog button on item click
body: <p>I have designed an alert dialog which contains list view. I want to enable the positive button of dialog only when an item is clicked else keep it disabled. I am unable to enable the button after click. Find my code below:</p>
  
  <pre><code>LayoutInflater inflater = LayoutInflater.from(getActivity());
  View view = (View)inflater.inflate(R.layout.action_list, null);
  
  AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
  alertDialogBuilder.setTitle("Select any action");
  alertDialogBuilder.setView(view);
  alertDialogBuilder.setInverseBackgroundForced(true);
  
  actionLV = (ListView)view.findViewById(R.id.action_list);
  actionLV.setAdapter(new ActionListAdapter(actionAL,getActivity()));
  
  alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
  
      public void onClick(DialogInterface dialog,int which) {
  
          // Write your code here to invoke YES event
          Toast.makeText(getActivity().getApplicationContext(), "You clicked on Cancel",
          Toast.LENGTH_SHORT).show();
      }
  });
  
  alertDialogBuilder.setPositiveButton("Done", new DialogInterface.OnClickListener(){
  
      public void onClick(DialogInterface dialog,int which) {  
  
          Intent intent = new Intent(getActivity(),LogItActivity.class);
          intent.putExtra("ACTION_NAME", ActionListAdapter.checkedActionName);
          startActivity(intent);
      }
  });
  
  AlertDialog alertDialog = alertDialogBuilder.create();
  
  alertDialog.setOnShowListener(new OnShowListener() {
          @Override
          public void onShow(DialogInterface dialog) {
              if(ActionListAdapter.checkedActionName != null){
                  done.setEnabled(true);
              }
          }
      });
  alertDialog.show();
  
  done = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
  done.setEnabled(false);
  if(ActionListAdapter.checkedActionName!= null){
      alertDialog.show();
  }
  </code></pre>
  
  <p>Someone please guide me.</p>