I would like to create a dialog that contains a link for my site (on android), and would want the phone's browser to open when the user clicks on the link. I currently have:
@Override
protected Dialog onCreateDialog (int id){
Dialog dialog = new Dialog(MyActivity.this); 开发者_JAVA百科
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("MyTittle");
ImageView image = (ImageView)dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.launcher_icon);
TextView lblClickable = (TextView)findViewById(R.id.text);
String htmlText = "Link to my <a HREF='http://www.rainbowbreeze.it'>site</a>";
lblClickable.setText(Html.fromHtml(htmlText));
//needed to enable click on the link
lblClickable.setMovementMethod(LinkMovementMethod.getInstance());
return dialog; }
the above code fires NullPointerException in the line that contains lblClickable.setText(Html.fromHtml(htmlText));
any suggestions? What's wrong with the code?
I think lblClickable
is null, this line is probably wrong:
TextView lblClickable = (TextView)findViewById(R.id.text);
corrected:
TextView lblClickable = (TextView)dialog.findViewById(R.id.text);
精彩评论