Xamarin.Android – Creating Lists and Opening the Browser

The ListView Control

aa1cTrKw7PEdW3

Displaying a list is one of the most common design patterns used in mobile applications. This makes the ListView control one of the most important design elements. In this lesson we will look at how to create a list of items in our app using the ListView control.

There is a great tutorial that digs in deeper with ListView controls and setting up custom adapters and layouts here: http://www.vogella.com/tutorials/AndroidListView/article.html

A ListView consists of the following parts:

Rows – The visible representation of the data in the list.

Adapter – A non-visual class that binds the data source to the list view.

Fast Scrolling – A handle that lets the user scroll the length of the list.

Section Index – A user interface element that floats over the scrolling rows to indicate where in the list the current rows are located.

There is a great tutorial that digs in deeper with ListView controls and setting up custom adapters and layouts here: https://developer.xamarin.com/guides/xamarin-forms/user-interface/listview/interactivity/

The primary classes:

ListView – user interface element that displays a scrollable collection of rows. On phones it usually uses up the entire screen (in which case, the ListActivity class can be used) or it could be part of a larger layout on phones or tablet devices.

View – a View in Android can be any user interface element, but in the context of a ListView it requires a View to be supplied for each row.

BaseAdapter – Base class for Adapter implementations to bind a ListView to a data source.

ArrayAdapter – Built-in Adapter class that binds an array of strings to a ListView for display. The generic ArrayAdapter<T>does the same for other types.

CursorAdapter – Use CursorAdapter or SimpleCursorAdapter to display data based on an SQLite query.

 Android includes built-in ListActivity and ArrayAdapter classes that you can use without defining any custom layout XML or code. The ListActivity class automatically creates a ListView and exposes a ListAdapter property to supply the row views to display via an adapter. The built-in adapters take a view resource ID as a parameter that gets used for each row. You can use built-in resources such as those in Android.Resource.Layout so you don’t need to write your own.

There is a lot of opportunity for customizing the appearance of the ListView control. Want to learn more? Check out this section – https://developer.xamarin.com/guides/android/user_interface/working_with_listviews_and_adapters/part_3_-_customizing_a_listview’s_appearance/

Opening the Browser

Android phones have a built-in browser with an intent filter that accepts the intent requests from other apps. To use this you have to have a URI (Uniform Resource Identifier) which is a string that identifies the resource of the Web site.

You may already be familiar with the term URL (Unform Resource Locator) – a URI is a URL with additional information that is needed for gaining access to resources required for posting the page.

We can use what we’ve previously learned about Intents to open the browser window.

Here is the video walk-through for this lesson that shows how to setup a ListView control and launch the browser window.

Leave a Reply

Your email address will not be published. Required fields are marked *