what is Android Adapter View?
Android Adapter Views
AdapterViews - > are views that can display multiple items. Common adapterViews are dropdownBox, Grid, Lists etc.
OptionsMenu->
Every activity can have it's own menu options, which can be activated by selecting from overflow icon(3 dots) on ActionBar of activity
Options for an activity are declared in menu.xml file in res/menu folder
->The syntax to declare menu items is
<menu>
<item
android:title="Help"
android:id="@+id/option_help"
/>
<item
android:title="clear"
android:id="@+id/option_clear"
/>
</menu>
---------------------------------
to display/load menu xml file override onCreateOptionsItem method in activity
code is
{
MenuInflator inf = getMenuInflator();
inf.inflate(R.menu.home_menu, menu);
}
-----------------------------
to handle menu item selection override onOptionsItemSelected method in activity, where you get the id of menu item which is selected by user
//-------------------------------------
to avoid restarting activity when device is rotated. Add below atribute in activity tag in manifest
android:configChanges="orientation|screenSize"
//------------------------------------------
== BaseAdapter class is used to create an Adapter for item_layout other than TextView.
-> The method in this class helps to generate layout of item as per requirement.
-> We need to override below 4 method to create custom adapter.
1. getCount() -> this method should return count of items you want to display on ListView or GridView.
2. getItem(int position) -> this method return an item object for a position, whose data to be displayed on ListView or GridView.
3. getItemId() -> this method should return a unique long value a id of the object at position. eg. itemno, srno, etc..
4. getView() -> it should return an Object of View class that represents item_layout filled with data of ith Object. This view will be added to listview or gridview. This method executes n-times decided by getCount() method.
Comments
Post a Comment