Last active
January 29, 2016 16:37
-
-
Save boloutaredoubeni/51c682db44ad38d11137 to your computer and use it in GitHub Desktop.
Custom Adapter Example
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
| import ...; | |
| public class MyCustomArrayAdapter extends ArrayAdapter<T> { | |
| final ArrayList<T> mArrayList; | |
| public MyCustomAdapter(Context context, ArrayList<T> list) { | |
| super(context, -1); | |
| mArrayList = list; | |
| } | |
| @Override | |
| public View getView(int position, View convertView, ViewGroup parent) { | |
| T myItem = mArrayList.get(position); | |
| Context context = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
| View view = inflater.inflate(R.id.my_row_layout_item, parent, false); | |
| SomeChildView childView = (SomeChildView) view.findViewById(R.id.my_child_view); | |
| childView.setSomethingInViewTo(myItem.getSomeAttribute()); | |
| return view; | |
| } | |
| @Override | |
| public int getCount() { | |
| return mArrayList.size(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment