[go: up one dir, main page]

0% found this document useful (0 votes)
21 views3 pages

10th Guided Exercise (WebView and AutoCompleteTextView)

The document provides instructions for an Android guided exercise involving a WebView and AutoCompleteTextView. It includes code to initialize the WebView, load URLs, and submit URLs from the AutoCompleteTextView to the WebView.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

10th Guided Exercise (WebView and AutoCompleteTextView)

The document provides instructions for an Android guided exercise involving a WebView and AutoCompleteTextView. It includes code to initialize the WebView, load URLs, and submit URLs from the AutoCompleteTextView to the WebView.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

University Of Makati 1

Android Development Guided Exercise

Guided Exercise #10: WebView and AutoCompleteTextView

Instruction:

1. Create an Android Application named


“TenthGuidedExercise”.
2. On activity_main.xml add the following
views and set their id’s
(see the image below)

3. On AndroidManifest.xml add this


uses-permission tag.

Sample Output

ANDROID DEVELOPMENT GUIDED EXERCISE CHRISTIAN MICHAEL MANSUETO


University Of Makati 2
Android Development Guided Exercise

MainActivity.java

public class MainActivity extends AppCompatActivity {

WebView browser;
AutoCompleteTextView suggestedURL;
ArrayAdapter adapter;
Button submit;
String [] urls = {"google.com","yahoo.com","facebook.com","youtube.com"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ge10_web_view_auto_complete_text_view );

browser = findViewById(R.id.webView );
suggestedURL = findViewById(R.id.actvURLGE10 );
submit = findViewById(R.id.btnOpenURLGE10);

adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1 ,urls);


suggestedURL.setThreshold(2);
suggestedURL.setAdapter(adapter);

initializeWebView();
loadWebURL();

public void initializeWebView(){


browser.getSettings().setLoadsImagesAutomatically(true);
// enabled java script
browser.getSettings().setJavaScriptEnabled(true);
// Android webview launches browser when calling loadurl
browser.setWebViewClient(new WebViewClient());
// enabled Scrollbar
browser.setScrollBarStyle(browser.SCROLLBARS_INSIDE_OVERLAY );
}

public void loadWebURL(){


submit.setOnClickListener(new View.OnClickListener () {
@Override
public void onClick(View view) {
String url = suggestedURL.getText().toString();

if(!url.startsWith("www.") && !url.startsWith("http://") ){


url = "www." + url;
}
if(!url.startsWith("http://") ){
url = "http://" + url;
}
browser.loadUrl(url);
}

ANDROID DEVELOPMENT GUIDED EXERCISE CHRISTIAN MICHAEL MANSUETO


University Of Makati 3
Android Development Guided Exercise

});
}
}

ANDROID DEVELOPMENT GUIDED EXERCISE CHRISTIAN MICHAEL MANSUETO

You might also like