vendredi 22 mai 2015

Grab custom view's children defined in XML and put into Dialog

Currently I'm working on a custom view that has to define specific dialog content depending on the place that is used:

main.xml

<com.example.MyView>

    <TextView android:text="Hello from Dialog"/>

</com.example.MyView>

My MyView class inflates different layout:

public class MyView extends RelativeLayout {

    public EntriesList(Context context) {
        super(context);

        inflate(context, R.layout.my_view, this);
    }

    public void openDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        // builder.setView();
        // Set all children from `main.xml` - in this case `TextView`

        builder.create().show();
    }

}

my_view.xml contains a button that opens dialog:

<RelativeLayout>

    <Button android:onClick="openDialog" />

</RelativeLayout>

How can I prevent from rendering TextView, grab it and push into the Dialog view ?

Aucun commentaire:

Enregistrer un commentaire