Android browser principle source code

Source: Internet
Author: User

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 );
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.