1

I just started android course and I am like native to it. I want to understand the below lines of code used in custom Array adapters.

public View getView(int position, View convertView, ViewGroup parent) {
// Check if the existing view is being reused, otherwise inflate the view
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}

Can you please explain the below details.

  1. What is the parameter definitions of View convertView, ViewGroup parent and can you please explain each parameter for better understanding.

  2. I understood what is LayoutInflater: it is used to inflate the layout for the view in the given context. But I didn't understand the Inflate method and it parameters. Can you please explain inflate(R.layout.list_item, parent, false) method and each of it parameters.

  3. I understood Position parameter in the getview declaration as below. Please correct me if I am wrong

Position is used to get the data from the arrayadapter for a particular position of the listview in the device. More over the data that will be populated is the data at the current index of the arrayadapter.

Please Note: I had searched android developers website, and blogs to understand the getview method. But no luck. Please assist.

Regards, Nithin.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
fed
  • 11
  • 1

0 Answers0