Looking for a Tutor Near You?

Post Learning Requirement » x
Ask a Question
x

Choose Country Code

x

Direction

x

Ask a Question

x

Hire a Tutor

Android Widgets - Spinner, WebView

Published in: Android Training
2,477 Views

This presentation contains basics of Spinner and WebView

Alok / Mumbai

8 years of teaching experience

Qualification: B.Tech/B.E. (RGPV, Bhopal - 2014)

Teaches: Computer, IT, CSS Training, HTML Training, Web Designing, Web Development, MBA Entrance, C, C++, C# (C Sharp), Java And J2EE, Visual Basic, Android Training, AJAX Training, Java Script

Contact this Tutor
  1. Chapter 2. Android App Development continued... Presentation by Abk Gupta Lecture Agenda : Creating Spinner, WebView, Browser Project & Basic Calculator Project
  2. Spinner Spinners p ovide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one. Presentation by Abk Gupta jay@gmail.com Home Home 'Work Other Custom
  3. Creating a Spinner 1. Create a spinner in the xml file and define the required attributes. < Spinner android:layout ntent" / > Presentation by Abk Gupta 2. The choices you provide for the spinner ca come from any source, but must be provided through an Adapter, such as an ArrayAdapter. For instance, if the available choices for your spinner are e-determined, you can provide them with a string array defined in a string resource file. Crea an array as shown in next slide in the string resource file.
  4. < ?xml version = "1.0" encoding < resources > < striåg-array name = " planets_array" > < item > Mercu ry < item > Earth < item > Mars Saturn < item > Neptune < [item > Presentation by Abk Gupta 3. Then connect the spinner in Java to xml view an create an adapter, set the adapter to the spinner. Spinner spinner = (Spinner) findViewByld(R.id.spinner); // Create an ArrayAdapter using the string array and a default spinner layout String[] planets_array =.getResources().getStringArray(R.array.foo array); ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, android.R.layout.simple spinner _ item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinner.setAdapter(adapter);
  5. 4. Optional Step : Implement the onltemSelectedListener on the listener. spinner.setOnlte SelectedListener(new AdapterView.OnltemSelectedListener() { @Override public void adapter\/iew, View view, int long l) { //wrlte your code here... Presentation by Abk Gupta @Override public void adapterView) {
  6. WebVie is a view that display web pages inside your application. You can also specify ML string and can show it inside your application using 1. WebView. WebView makes turns your application to a web application. Steps to add a WebView to y ur Android Application. Presentation by Abk Gupta In order to add WebView to our application, you have to add element to your xml layout file. Its syntax is as follows - < WebView xmlns:android = " http://schemas.android.com/apk/res/android"
  7. 2. Attach the WebView created in xml file to Java code using findViewByld() method. 3. Now, we can o en any URL in the WebView by using webView.loadUrl("http: /www.facebook.com"); Note : We need to add INTERNE! access permission in our Manifest file, otherwise we will get error Presentation by Abk Gupta 4. Once a URL is loaded, when we click on any link, it automatically opens the Android default browser and opens the link o that, if we need to override this behavior, we should use: webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return super.shouldOverrideUrlLoading(view, url);
  8. WebView methods web\/iew. clearH istory(); getTitle(); getUrl(); loadData(); Presentation by Abk Gupta String data = " < bodY> Hello, Javatpoint! " webview.loadData(data, "text/html", "UT F-8"); Project : Create a small browser application, that can tak a url from user and load its contents.
  9. Presentation by Abk Gupta END OF LECTURE