I need help to correct my codes.
I am trying to write code what direct ImageButton
click to view html content.
Can any one help. ImageButton
is not showing content, only thing load is layout
I need help to correct my codes.
I am trying to write code what direct ImageButton
click to view html content.
Can any one help. ImageButton
is not showing content, only thing load is layout
If you want an ImageButton with a link to a web page then try this:
On the view, configure android:OnClick with the name of the function you will call
<ImageButton
android:id="@+id/myImageButton"
android:onClick="viewHTMLContent"
/>
Then go to your class and configure the Onclick function like this:
public class MyClass extends Activity{
ImageButton myImageButton;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myLayout);
myImageButton=(ImageButton)findViewById(R.id.myImageButton);
}
public void viewHTMLContent(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(browserIntent);
}
}
if you want use your own html into a TextView(example), then you need to modify the viewHTMLContent() function:
public void viewHTMLContent(View v) {
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description</p>"));
}
follow this thread for more info How to display HTML in TextView?