Reputation: 120
I have one custom adapter that displays contacts from the phone List and buttons against it. As the title says filter is working fine (list count changes) but listview keeps the same data, if count is 3 listview shows top 3 entries.
Class for adapter:
public class UserCustomAdapter extends ArrayAdapter<User> {
Context context;
int layoutResourceId;
ArrayList<User> data = new ArrayList<User>();
public UserCustomAdapter(Context context, int layoutResourceId,
ArrayList<User> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
UserHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new UserHolder();
holder.textName = (TextView) row.findViewById(R.id.textView1);
holder.number = (TextView) row.findViewById(R.id.textView2);
holder.textLocation = (TextView) row.findViewById(R.id.textView3);
holder.btnEdit = (Button) row.findViewById(R.id.Share);
holder.btnInvite = (Button) row.findViewById(R.id.button2);
row.setTag(holder);
} else {
holder = (UserHolder) row.getTag();
}
final User user = data.get(position);
holder.textName.setText(user.getName());
holder.number.setText(user.getNumber());
holder.textLocation.setText(user.getLocation());
if(user.isMember())
holder.btnInvite.setVisibility(View.INVISIBLE);
return row;
}
the user class is
public class User {
String name;
String number;
String location;
boolean member;
@Override
public final String toString(){
Log.e("Sent to filter", name);
return name;
}
+plus all getters and setters
}
Upvotes: 2
Views: 155
Reputation: 157437
you should use
final User user = getItem(position);
instead of
final User user = data.get(position);
since you are relying on the Filter
implementation of ArrayAdapter
.
Upvotes: 1