I'm popping up an AlertDialog when a ListView item is clicked and the string of the message is very large (nearly 20,000 characters). What winds up happening is that I click the list item and it sits for about 3-4 seconds before displaying the AlertDialog. This is problematic for many reasons, primarily that the user could click the button repeatedly and crash the app.
My first thought was to try to mimic how the Google Play app handles their open source license display (Play -> Nav Drawer -> Settings -> Open Source License info), where they pop open the AlertDialog and then it looks as though the view/text is loaded after the dialog is shown. I imagined it looking something like this:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(title);
builder.setMessage(veryLongStringMessage);
builder.setCancelable(true);
builder.setNeutralButton(android.R.string.ok, listener);
final AlertDialog alertDialog = builder.create();
alertDialog.show();
Pretty basic stuff up until this point. Then I've tried to remove the message set in builder for something like:
builder.setMessage("")
// create/show dialog as above
alertDialog.setMessage(veryLongStringMessage);
But that seems to just load the whole dialog before showing it. So I thought maybe post a runnable to go at the end of the activity calls, and that wasn't working. I tried doing this in an Async task and could not get it working that way either. I've tried this as a DialogFragment where I call
activity.getSupportFragmentManager().executePendingTransactions();
Then go on to try to set the message after I know the DialogFragment has been shown and I either wind up with an empty dialog (the new message won't show up) or it loads it all at once and I'm sitting with that 3-4 second delay.
Anyone have any good method of implementing and AlertDialog with a very large message?