0

How can I get and show content from url by pressing a button in android? The button is in xml, and I need to show display information below.

Button --> information from http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=1

My wrong code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bovalpo);

    Button ButtonOne = (Button)findViewById(R.id.btn);

    ButtonOne.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
          Intent viewIntent =

            new Intent("android.intent.action.VIEW",
            Uri.parse("http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=1"));
            startActivity(viewIntent);
        }
    });
Tim
  • 35,413
  • 11
  • 95
  • 121

2 Answers2

1

Your Intent is wrong. Try using:

Intent intent = new intent(Intent.ACTION_VIEW, Uri.parse("http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=1"));
startActivity(intent);
Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
0

If you want to present information from link in the same view in which you press the Button, then don't use Intent, because it gets you to another view.

What you might want to use is AsyncTask (about) that would get informations via internet in background, and then present it below button, or anywhere else on screen.

To make a web connection use:

url = new URL("http://...");
urlConnection = url.openConnection();
InputStream inputStream = urlConnection.getInputStream();

And to get web data, try code shown in this topic.

Hope this helps.

Community
  • 1
  • 1
cyborg86pl
  • 2,597
  • 2
  • 26
  • 43