0

I watched some videos but i did not understand why we use getView method in custom adopter in android. Can anyone explain that what does getView method do in array adopter. Thanks in advance.

Awais
  • 117
  • 9

2 Answers2

0

Well you need to read and watch more But nothing help better than testing. getView() is getting view ;) Getting Each Item of Adapter to Access Each Elements. For example you create ListView and set Custom Adapter. and for each item in list you have some other child views. Image of People (ImageVIew) and Name (TextView) & etc. to access and modify each of these elements you call getView in Adapter Class. Take look and test this Example: Tutorial for Custom Adapter

modify and destroy it to understand how it works. Good Luck

Elias Fazel
  • 2,093
  • 16
  • 20
0

Basically you have a View(the simple building block) and then you have AdapterView which takes some data and then fits the data at appropriate place.

Each AdapterView has a number of View object to fit the data. For example if you have a ListView to show the name each planet, then basically you have

Mercury --->Row 1 to View object1

Venus --->Row 2 to View object2

Earth --->Row 3 to View object3

Mars --->Row 4 to View object4

... other rows

now if you want to know which item or row was clicked then you need to attach a listener to the ListView and then use the getView() method to know which row was clicked.

Doc
  • 10,831
  • 3
  • 39
  • 63