public static void show(final Activity context, @NonNull final Geocache cache, @Nullable final Runnable afterVoteSent) {
        final View votingLayout = View.inflate(context, R.layout.vote_dialog, null);

        final CacheVotingBar votingBar = new CacheVotingBar();

        final AlertDialog.Builder builder = Dialogs.newBuilder(context);
        builder.setView(votingLayout);
        builder.setPositiveButton(R.string.cache_menu_vote, (dialog, which) -> vote(cache, votingBar.getRating(), afterVoteSent));
        builder.setNegativeButton(android.R.string.cancel, (dialog, whichButton) -> dialog.dismiss());
        final AlertDialog dialog = builder.create();

        votingBar.initialize(cache, votingLayout, stars -> {
            final Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            // this listener might be fired already while the dialog is not yet shown
            if (button != null) {
                final IConnector connector = ConnectorFactory.getConnector(cache);

                button.setEnabled(connector instanceof IVotingCapability && ((IVotingCapability) connector).isValidRating(stars));
            }
        });
        dialog.show();
        final IConnector connector = ConnectorFactory.getConnector(cache);
        dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(connector instanceof IVotingCapability && ((IVotingCapability) connector).isValidRating(cache.getMyVote()));
    }
Small dialog showing only a rating bar to vote for the cache. Confirming the dialog will send the vote over the
network (in the background).
main/src/main/java/cgeo/geocaching/gcvote/VoteDialog.java