android - Show dialog before opening autoLink in TextView -



android - Show dialog before opening autoLink in TextView -

i using android:autolink="web" in textviews convert urls clickable links. works great. since links user-generated want inquire user dialog beforehand, whether want openthis link.

i haven't found anything, there way intercept click , show dialog before forwarding typical action_view intent?

try add together textview properties like:

<textview android:text="http://www.google.com" android:layout_width="wrap_content" android:layout_height="wrap_content" android:autolink="web" android:onclick="onurlclick" android:linksclickable="false" android:clickable="true" />

and override onclick method like:

public void onurlclick(final view view) { alertdialog.builder builder = new alertdialog.builder(getactivity()); builder.setpositivebutton("yes", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { textview mytextview = (textview)view; string myurl = string.valueof(mytextview.gettext()); intent browse = new intent( intent.action_view , uri.parse(myurl) ); startactivity( browse ); } }); builder.setnegativebutton("no", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { } }); alertdialog dialog = builder.create(); dialog.show(); }

it worked me. example, practice should separate creation onclick method.

android android-intent hyperlink textview autolink

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -