简体   繁体   中英

how to textview and android

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);                                                

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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM