1 / 18

Android

Android. Customizaiton of Layouts. A better task list. Use a new Activity- ListActivity Learn about listViews Learn about adapters Learn about some more eclipse refactoring skills. Task Manager . Cast of characters.

suchin
Download Presentation

Android

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android Customizaitonof Layouts

  2. A better task list • Use a new Activity-ListActivity • Learn about listViews • Learn about adapters • Learn about some more eclipse refactoring skills.

  3. Task Manager

  4. Cast of characters • ListView – a view made for displaying a collection of data in a list of child views. • ListActivity – an activity made for managing a ListView, An activity that displays a list of items by binding to a data source such as an array • ListAdapter – a class that acts as a dataprovider for a listView.

  5. ListActivity • ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code) (as we did in TaskManager Application) • Optionally, your custom view can contain another view object of any type to display when the list view is empty. This "empty list" notifier must have an id "android:id/empty". Note that when an empty view is present, the list view will be hidden when there is no data to display

  6. Diff between android:gravity and android:layout_gravity • android:gravitypositions the contents of that view (i.e. what’s inside the view), whereas android:layout_gravity positions the view with respect to its parent (i.e. what the view is contained in).

  7. Refactoring:Extracting Android String • Very nice way to put a String into Android XML and extract it to res/values/strings.xml.

  8. Step-one (the listView)

  9. Listview • ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list

  10. No Data View Steps

  11. Show the tasks STEP 2

  12. How a ListAdapter supports a listVies

  13. Show Tasks Steps

  14. Why I should create CustomLayout??? • The number of rows to be present on the screen is to be decided dynamically as per the tasks stored in the array.. So i cannot hard code the complete view in XML.

  15. Context class As the name suggests, its the context of current state of the application/object. It lets newly created objects understand what has been going on. Typically you call it to get information regarding another part of your program (activity, package/application) You can get the context by invoking getApplicationContext(), getContext(), getBaseContext() or this (when in the activity class). Typical uses of context: 1)Creating New objects: Creating new views, adapters, listeners: TextViewtv = new TextView(getContext()); ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...); 2)Accessing Standard Common Resources: Services like LAYOUT_INFLATER_SERVICE, SharedPreferences: context.getSystemService(LAYOUT_INFLATER_SERVICE) getApplicationContext().getSharedPreferences(*name*, *mode*); 3)Accessing Components Implicitly: Regarding content providers, broadcasts, intent getApplicationContext().getContentResolver().query(uri, ...);

  16. Android:checkmark Drawable used for the check mark graphic. Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name". Constant Value: 16843016 (0x01010108)

  17. @+id/android:list and @+id/list • Resource IDs in Android are specific to a package (which is good, or else you'd have lots of conflicts if your app is dealing with several packages at the same time). • @+id/list will create a resource ID in your app (=your package) with the name "list" and give it a unique ID. In code, that would be R.id.list. • @android:id/list will use the ID "list" from the package android (which, in code, would beandroid.R.id.list

More Related