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);
}
});
If you want to present information from link in the same view in which you press the
Button, then don’t useIntent, 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:
And to get web data, try code shown in this topic.
Hope this helps.