[ACCEPTED]-How does ArrayAdapter getView() method works?-android-arrayadapter
getView()
is the main part of your adapter. It returns 12 View
that will be displayed as your list/grid/gallary/any 11 view that use adapter item. It triggers 10 when you scroll the view(list for example).
So 9 the first thing you should do its to create 8 your custom adapter. You may extend it from 7 BaseAdapter
. Then you need to create some data to display 6 (or pass it to adapter from out side - its 5 better solution).
After that override getView()
method 4 and make sure to return your custom View 3 there. In your case it should be a Layout
with 2 ImageView
and TextView
(and dont forget to fill them).
You 1 can learn more from :
in BaseAdapter
you have getView
function that is called by 13 for an AdapterView
i.e. ListView
.
you need to override getCount
method 12 of the BaseAdapter to return total number 11 of views to diplay.
And in getView you get 10 following things:
public View getView(int position, View convertView, ViewGroup parent)
position:
getView going 9 to be called for each position every time it is displayed.
convertView
As 8
getView
is call many times inflating a new view 7 every time is expensive so list view provides 6 you one of the previously created view to 5 re-use.parent
A reference to the parent 4 view that this view will be a child of.
ArrayAdapter
is 3 a subclass of BaseAdapter
which takes ArrayList
(or array) in 2 constructor.
And overrides getCount
for you.
So all 1 you need to implement is getView
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.