Implement a simple browser function:
:
You see, you can add a net...
Control Code:
Package org. example. browserintent;
Import org. example. browserintent. R;
Import Android. App. activity;
Import Android. content. intent;
Import android.net. Uri;
Import Android. OS. Bundle;
Import Android. View. keyevent;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. View. View. onkeylistener;
Import Android. widget. Button;
Import Android. widget. edittext;
Public class browserintent extends activity {
Private edittext urltext;
Private button gobutton;
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
// Get a handle to all user interface elements
Urltext = (edittext) findviewbyid (R. Id. url_field );
Gobutton = (button) findviewbyid (R. Id. go_button );
// Setup event handlers
Gobutton. setonclicklistener (New onclicklistener (){
Public void onclick (view ){
Openbrowser ();
}
});
Urltext. setonkeylistener (New onkeylistener (){
Public Boolean onkey (view, int keycode, keyevent event ){
If (keycode = keyevent. keycode_enter ){
Openbrowser ();
Return true;
}
Return false;
}
});
}
Private void openbrowser (){
Uri uri = URI. parse (urltext. gettext (). tostring ());
Intent intent = new intent (intent. action_view, Uri );
Startactivity (intent );
}
}