I have asked this question to almost everybody and got same answer.
Question : I designed a custom adapter because my ListView rows have a checkbox and a TextView. getView() method has a setOnClickListener() method and when I click the checkbox on application, is getView() method is invoked with setOnClickListener() or only setOnClickListener() executed ?
Answer : Only setOnClickListener() is executed.
New Question : If it is so, when clicking the checkbox in third row of the ListView, How is pos
variable set to 2(It already must be 2 because index of third row is 2 but what assigns 2 into pos
) ?
public View getView( int position, View convertView, ViewGroup parent ){
View rowView = myInflater.inflate( R.layout.model_row, null );
final int pos = position;
TextView textView = (TextView) rowView.findViewById( R.id.text );
final CheckBox checkBox = (CheckBox) rowView.findViewById( R.id.checkbox );
textView.setText( myList.get(position).getContent() );
checkBox.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
if( checkBox.isChecked() ){
myList.get( pos ).setChecking( checkControl.Checked );
}
else{
myList.get( pos ).setChecking( checkControl.NonChecked );
}
}
});
return rowView;
}
Aucun commentaire:
Enregistrer un commentaire