Skip to content

Instantly share code, notes, and snippets.

@olkunmustafa
Created July 11, 2016 17:58
Show Gist options
  • Save olkunmustafa/269fb9b041204c71047559bfa5d9d6ed to your computer and use it in GitHub Desktop.
Save olkunmustafa/269fb9b041204c71047559bfa5d9d6ed to your computer and use it in GitHub Desktop.
It can be used creating new BaseAdapters. It makes easier the process.
package com.verisun.core;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import java.util.ArrayList;
public abstract class SimpleBaseAdapter<T> extends BaseAdapter {
private ArrayList<T> list;
public SimpleBaseAdapter() {
}
public void setList(ArrayList<T> list) {
this.list = list;
notifyDataSetChanged();
}
@Override
public int getCount() {
return list != null ? list.size() : 0;
}
@Override
public T getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public abstract View getView(int position, View convertView, ViewGroup parent);
public T deleteItem(int position) {
if (list != null && list.size() > position) {
T item = list.remove(position);
notifyDataSetChanged();
return item;
}
return null;
}
public boolean deleteItem(T item) {
if (list != null && list.remove(item)) {
notifyDataSetChanged();
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment