0

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

  • 2
    share your code how fare you try.. –  Jul 29 '16 at 05:38
  • Welcome to SO, please be a bit more specific when asking question: what have you tried, what do you expect, etc. See [how to ask](http://stackoverflow.com/help/how-to-ask) – Nehal Jul 29 '16 at 05:40
  • Where you want to show html content? –  Jul 29 '16 at 06:07

1 Answers1

1

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?

Community
  • 1
  • 1
El0din
  • 3,208
  • 3
  • 20
  • 31
  • Hi bro....... you don't need to implements OnClickListener and myImageButton.setOnClickListener(this); when you declare android:onClick="viewHTMLContent" –  Jul 29 '16 at 09:24