简体   繁体   中英

How to create a popup with a scroll view programmatically?

I need to create a popup window programmatically, with a scrollview is this possible? i need to do everything in java side.

I was using a alert dialog but maybe is better a popup window, but didn't find much information on how to do it programatically.

i was using this code for the alert dialog

  AlertDialog.Builder alert = new AlertDialog.Builder(OFActivityA.this);
        alert.setTitle("Something");
        alert.setText("fe");
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                //what you need to do after click "OK"
            }

        });
        alert.show();

i need to do everything in java side. , not really - you can create your custom dialog with a custom layout and have any kind of layout that you would like to have.

For example, create dialogClass:

public class ProgressDialog extends Dialog {

public ProgressDialog(@NonNull Context context) {
    super(context);

    setContentView(R.layout.progress_dialog); //this is your layout for the dialog

    }
}

And all you need to do to show your dialog is call those line:

ProgressDialog progressDialog = new ProgressDialog(getContext());
progressDialog.show(); // this line shows your dialog

You can put all your logic into the class using java as you want to only that now you can control your layout and how it looks in easier way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM