180 likes | 369 Views
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.
E N D
Android Customizaitonof Layouts
A better task list • Use a new Activity-ListActivity • Learn about listViews • Learn about adapters • Learn about some more eclipse refactoring skills.
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.
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
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).
Refactoring:Extracting Android String • Very nice way to put a String into Android XML and extract it to res/values/strings.xml.
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
Show the tasks STEP 2
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.
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, ...);
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)
@+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