Denys Karpov
Denys Karpov

Reputation: 43

How show dialog like a picture with imagebutton

Hi_i wanna create some dialog(which i understand it's better variant for me) which consist so,e image and image button on this image/ Dialog vill be calling by method onClick Pleas recommend me shortest variant of realization (actually about visual representation, it must be the next: after clicking on the button layout became little dark or grey and in the center of layout creates my picture with button) If Dialog not useful in this case recommend me something else

Upvotes: 0

Views: 607

Answers (1)

Avijit
Avijit

Reputation: 3824

Try like this:

Button d = (Button) findViewById(R.id.btnId);
    d.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Fragment1 dialogFragment = Fragment1.newInstance(null);
            dialogFragment.show(getFragmentManager(), "dialog");
        }
    });

And create a class Fragment1 like this in you .java file like this:

public static class Fragment1 extends DialogFragment {

    static Fragment1 newInstance(String title) {
        Fragment1 fragment = new Fragment1();
        Bundle args = new Bundle();
        args.putString("title", title);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        LayoutInflater adbInflater = LayoutInflater.from(getActivity());
        View eulaLayout = adbInflater.inflate(R.layout.your_xml, null);
        Button btn_OK = (Button) eulaLayout.findViewById(R.id.BTNok);
        dialog.setContentView(eulaLayout);
        btn_OK.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        return dialog;
    }
}

your_xml is your xml file to show the dialog.

Edited

In your code you have import like this:

import android.support.v4.app.DialogFragment;

Change it to:

import android.app.DialogFragment;

And lastly as it requires the api level above 11 it will through some error. So you have to make a chnge in your manifest like this:

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="17" />

This will might help you.

Upvotes: 1

Related Questions