Frage

Trying to inflate an AlertDialog.Builder. I'm trying to get the date wheel (Yuri Kanivets' wheel) to appear inside of my dialog. Since the exact code that I need exists inside one of his classes, I'm just trying to instantiate a new instance of his DateActivity class (which I've imported into my project), and then add that to my dialog. Unfortunately, I can't seem to connect my DateActivity object with my dialog. I thought that it would be one of the arguments where I inflate the view, but that crashes. Here's my code:

EDIT: To clarify, in the code that follows there are no errors. The problem as I mentioned is that there is no usage, and therefore no connection, of my DateActivity variable with the AlertDialog.Builder. I've tried using that variable (dateWheelSelector) as an argument to builderView and also to the builder variable instantiations, but both of these crash. I need to figure out how to connect these since right now my dialog is empty.

private void setStartDate() {

    //somehow I need to use this variable, but where???
    DateActivity dateWheelSelector = new DateActivity();

    LayoutInflater inflater = LayoutInflater.from(this);

    View builderView = inflater.inflate(R.layout.wheel_date_layout, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(builderView);       
    alert = builder.create();

    /* Set the title of this dialog programatically */
    TextView title = (TextView) builderView.findViewById(R.id.date_title);
    title.setText("Choose Start Date");

    alert.show();
}

Thanks for any suggestions.

War es hilfreich?

Lösung

You cannot add an Activity to a dialog. You can either define the Activity to be a Dialog (see Android Activity as a dialog) or you can refactor your DateActivity to be a DialogFragment (see http://developer.android.com/reference/android/app/DialogFragment.html) that can be used as Fragment or as Dialog.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top