When am coding android I came across the following thing
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
convertView = _inflater.inflate(R.layout.abstract_list_row_item, null);
move.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// if btn is clcked then data is changed an we need to refresh framents
MainAppDataController.getInstance().setIsDataChanged(true);
callWhiteListDB = new CallWhiteListDB(_context);
callWhiteListDB.openToWrite();
callWhiteListDB.insert(allContacts.get(position).name, allContacts.get(position).number);
callWhiteListDB.close();
callBlackListDB = new CallBlackListDB(_context);
callBlackListDB.openToWrite();
callBlackListDB.deleteSingleItem(allContacts.get(position).dbId);
callBlackListDB.close();
populateList(position);
notifyListView(view);
}
});
return convertView;
In the above example getView()
method has parameters like int position, View convertView, ViewGroup parent.My Observation was as soon as I start using position variable inside onclick()
, Eclipse throws compilation error and asks make position as final. Why should I make it as final? AFAIK final is used for constants.