ARTICLE AD BOX
I'm trying to load an HTML file in an AlertDialog and have links clickable and have dialog properly formatted with padding.
The following code shows the dialog box, but the link is not clickable.
public void showNews(int number) { int last = shared.getInt("news",1); Log.d("News", String.valueOf(last)); if (last >= number) return; AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this, R.style.darkAlertDialog); //, R.style.darkAlertDialog builder.setTitle("Application News"); StringBuilder text = new StringBuilder(); BufferedReader reader = null; try { reader = new BufferedReader( new InputStreamReader(getAssets().open("html/" + "news.html"))); String mLine; while ((mLine = reader.readLine()) != null) { text.append(mLine); text.append('\n'); } } catch (IOException e) { Toast.makeText(getApplicationContext(),"Error reading file!",Toast.LENGTH_LONG).show(); e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { Log.e("showNews", "Error reading file"); return; } } } // Trouble Spanned result; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { result = Html.fromHtml(text.toString(), Html.FROM_HTML_MODE_LEGACY); } else { result = Html.fromHtml(text.toString()); } builder.setMessage(result); // result.setMovementMethod(LinkMovementMethod.getInstance()); // result.setClickable(true); // Trouble builder.setPositiveButton( "Okay", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // prefs.putInt("news", number); // prefs.apply(); dialog.dismiss(); } }); builder.create(); builder.show(); }The set movement and set clickable gives a syntax error
If I replace the section between // Trouble, as suggested by Using HTML in Android Alert Dialog with
TextView msg = new TextView(this); msg.setText(Html.fromHtml(String.valueOf(text))); builder.setView(msg); msg.setMovementMethod(LinkMovementMethod.getInstance()); msg.setClickable(true);the link is clickable but there is no padding between the text and the dialog box.

