Archives for: July 2010, 31
ListActivity Cheetsheet
July 31st, 2010ListActivity contains in android.app.
ListView
Custom define Activity Layout
ListActivity hosts a ListView object. User can set a custom layout for activity, but make sure that it contains a ListView which id is @id/android:list
Set empty view
- Define <FrameLayout> in resource layout file which contains empty view and list view
- At onCreate() call getListView().setEmptyView(findViewById(R.id.empty)
ListAdapter
ListActivity uses ListAdapter to get data and custom sub view.
User generally extends BaseAdapter to define his own adapter.
Basic overriding methods
public int getCount()Get total number of listpublic Object getItem(int position)Get the data/reference to data at postionpublic long getItemId(int position)Get the unique id of datapublic View getView(int position, View convertView, ViewGroup parent)Create a view for position. If convertView is not null, it pointer to previous created view, you can reuse it.
Selectable and Clickable
areAllItemsEnabled()/isEnabled() are overriding to set view selectable and clickable.
Separator
Add a list item view, and disable it, and it will serve as a separator.
Expandable list
Solution 1: Make item view contains several views which can be configure visiuable or not visiuable.
Notify Data Change
notidyDataSetChanged()