I looked at a lot of examples and managed to get this far, but i still can't get the button to delete the item from my array. How do i utilize remove(position) correctly?
public class adapter extends ArrayAdapter {
public adapter(Context context, ArrayList<User> users) {
super(context, 0, users);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
User user = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.activity_main, parent, false);
}
TextView question = (TextView) convertView.findViewById(R.id.question);
TextView answer = (TextView) convertView.findViewById(R.id.answer);
question.setText(user.name);
answer.setText(user.hometown);
ImageButton remove = (ImageButton) convertView.findViewById(R.id.removeButton);
remove.setTag(position);
remove.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
notifyDataSetChanged();}
});
return convertView;
}
}
User List
public class User {
public String name;
public String hometown;
public User(String name, String hometown) {
this.name = name;
this.hometown = hometown;
}
public static ArrayList<User> getUsers() {
ArrayList<User> users = new ArrayList<>();
users.add(new User("Hi", "hi"));
users.add(new User("Marla", "San Francisco"));
users.add(new User("Sarah", "San Marco"));
return users;
}
}