I am trying to extend baseAdapter. and get the object inside onClick event. But its saying that, obj needs to be declared final. Someone, told me that the obj(aStudent) cant be found inside the click event?if so, why?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) adapterContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.custome_adapter_list_row_item, parent, false);
TextView lblStudentName = (TextView) rowView.findViewById(R.id.lblStudentName);
TextView lblStudentAge = (TextView) rowView.findViewById(R.id.lblStudentAge);
Button btnNext = (Button) rowView.findViewById(R.id.lbllist);
**final Student aStudent = studentDataHolder.get(position);**
if (aStudent != null) {
lblStudentName.setText(aStudent.getName());
lblStudentAge.setText("Age : " + aStudent.getAge());
btnNext.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(adapterContext, "Position is"+aStudent.getName(), Toast.LENGTH_LONG).show();
}
});
}
return rowView;
}
as, far as i understand, the code is making a new object of Student everytime its fetching a row from the array. Am i wrong? But still again, why final?