I have an adapter where I load my users and one button/textfiled for send invitations. In the adapter I do this:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
UserAgenda ua = getItem(position);
ViewHolder holder;
if (convertView == null) {
//...
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if(ua.getInvited() != null){
if(ua.getInvited().equals("true")){
addTextViewInvited(convertView);//add a textview as the user is invited
}
else if(ua.getInvited().equals("false")){
addButton2Invite(convertView,ua);//add the button to invite
}
}
return convertView;
}
And on the method of addButton2Invite I send the invitation as:
private void addButton2Invite(final View convertView, UserAgenda ua) {
bt2Invited.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
final Button bt2Invited = (Button) convertView.findViewById(R.id.bt2invite);
final ProgressBar pbar = (ProgressBar) convertView.findViewById(R.id.progress);
new Thread(){
@Override
public void run() {
if(networkWork())
ua.setInvited("true"); //Error, NOT PERMITED! ua need to be final.
};
}.start();
}
});
}
When the networkWork is OK, I want to set the ua.setInvited("true"); but that is not permited if I dont declare ua as final. But then I cant change its value and next time the adapter enters on getView will find the ua.getInvited() = "false". When I scroll down/up the textview and the button appear on the row.
Any ideas to change the value of the object UserAgenda ua within the onClicklistener?
Thanks!
declare the ua final because when at ua.setInvited(true); you are changing a value in object refrenced by ua not the refrence of ua so by setting ua final will not affect your setInvited(true)
otherwise you have to use click listener by implementing it in your activity class like
and using
and implementing the method of