6568

How to show a Progress Bar inside an AlertDialog Builder along with other elements without an XML?

Question:

I am trying to create an AlertDialog for a Bluetooth transfer after the transfer notification is touched in an android phone.

I am trying something like this: Out of the below, I am getting everything - icon, title and two buttons. I am sure I can add other info like From, FileName and others using cursors with the help AlertDialog.Builder properties. I just do not know to get a progress-bar in it. I do not want to use an XML.

protected Dialog onCreateDialog(int id) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setIcon(R.id.imageFile); alertDialogBuilder.setTitle("File Transfer"); ProgressDialog progressDialog; Context mContext = null; progressDialog = new ProgressDialog(mContext); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); //alertDialogBuilder.setView(progressDialog); //STUCK HERE //"!" icon and "File Transfer" //from : device name //File: <name> //Type: <type> (<size>) //Receiving/Sending File //<%> | Green progress bar //Hide and Stop buttons alertDialogBuilder.setPositiveButton("STOP", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); alertDialogBuilder.setNegativeButton("HIDE", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); return alertDialog; }

I have everything in place except I am not able to figure out how to bring a progress-bar here.

Can I getjust a progress-bar using XML layout and use as

alertDialogBuilder.setView(R.id.what-ever-xml-file) Or how to create a view for that progress-bar in he Java file itself and put a progressbar in that view and then put that view inside the dialog.

I want sth like this:

<img alt="Alert Dialog with ProgressBar" class="b-lazy" data-src="https://i.imgur.com/WYBMy.png" data-original="https://i.imgur.com/WYBMy.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

Answer1:

You can use <strong>Dialog</strong> and add ProgressBar on this by using

_dialog.addContentView(view, params) method.

Recommend

  • Android Theme Issue using AlertDialog.Builder
  • How to update friends image like whatsApp with Firebase
  • How to receive form data and process the data in Web API
  • Problems When Trying to display images from Parse using Swift
  • Android: ActivityNotFoundException occasionally encountered when trying to send MMS on specific devi
  • animationDrawable is not playing in Actionbar?
  • ActionBar and Fragments on ICS 4.0.3
  • NSImage returns nil even when png file is in Resource folder
  • Trigger click on leaflet marker
  • Download image using XMLHTTPRequest
  • wrap content in JavaFX
  • Styling tabBar-indicator with ActionBarSherlock
  • Chart js - Draw center of each bubbles of a bubble chart
  • Android toolbar overflow menu change text color and fill menu to the screen
  • Google script gmail addon update TextInput value,on change function
  • Facebook API: cannot login on Android
  • Returning this from a constructor function in JS
  • dismiss Progress Dialog in another Activity … Android
  • ASP.NET RegularExpressionValidator, validate on a non-match?
  • How to remove all of a jQuery UI dialog when it is closed
  • Replace Fragment with another on back button
  • Adding Parent and Child Nodes in TreeView from Sql Server 2008
  • How to upload specific List image using click on Upload button
  • Bad interaction between Zope2 XML-RPC and AT Image mutator?
  • Blackberry 6: how to detect a long click on track pad?
  • unable to get jsonEncode in magento2
  • Authentication failed with Azure Active Directory in Windows Phone
  • How to get listview position?
  • Autofac with Web API 2 - Parameter-less constructor error
  • Laravel: Getting Session ID oddly truncates when using foreach
  • Bypass multiple inheritance in Java
  • Visual Studio 2010 debugger build correctly - compiler pdb and linker pdb not in synch?
  • Alert pop up with LWUIT
  • Recording logins for password protected directories
  • how to do an event when i swipe from fragment to the other
  • Why winpcap requires both .lib and .dll to run?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j