Last active
August 29, 2015 14:24
-
-
Save SelvinPL/bb4f8aebb129f1db9420 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MinimalArrayAdapter<T> extends BaseAdapter { | |
| LayoutInflater inflater = null; | |
| ArrayList<T> mObjects = null; | |
| public MinimalArrayAdapter(Context ctx, ArrayList<T> list) { | |
| mObjects = list; | |
| inflater = LayoutInflater.from(ctx); | |
| } | |
| @Override | |
| public int getCount() { | |
| return mObjects.size(); | |
| } | |
| @Override | |
| public T getItem(int position) { | |
| return mObjects.get(position); | |
| } | |
| @Override | |
| public long getItemId(int position) { | |
| return position; //or ((T)getItem(position)).getId(); if we had ... but then you should also override hasStableIds | |
| } | |
| @Override | |
| public View getView(int position, View convertView, ViewGroup parent) { | |
| if(convertView == null) | |
| convertView = inflater.inflate(android.R.layout.simple_list_item_1, parent, false); | |
| T item = getItem(position); // why getItem not direct access ... if you add filtering someday you shouldn't wory about this ... | |
| /* setup view based on item*/ | |
| return convertView; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment