tags:

views:

238

answers:

2

Firstly I am new to android and Java so this is a beginners question.

I have some code that overrides the ArrayAdapter's getView method. Here is the code

public View getView(int position, View convertView, ViewGroup parent) {
   TextView label = (TextView)convertView;
   if (convertView == null) {
      convertView = new TextView(ctxt);
      label = (TextView)convertView;
   }
   label.setText(items[position]);
   return (convertView);
}

My question is: why does label.setText(items[position]); affect the convertView return value? How are they related / linked?

A: 

TextView label = (TextView)convertView; doesn't set label to be a copy of convertView, it is convertView. It's a reference to the same object. So when you do label.setText(items[position]);, it does it on convertView.

AaronM
A: 

Looking at your code convertView and label are two variables that both reference the same TextView object. Whatever you do with either variable will be reflected in the TextView object they reference.

mbaird