Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. public class TripGroupAdapter extends BaseAdapter {
  2. private static final String TAG = LogUtils.makeTag(TripGroupAdapter.class);
  3.  
  4. private Context mContext;
  5.  
  6. private List<TripGroup> mGroups;
  7.  
  8. private Query mQuery;
  9.  
  10.  
  11.  
  12. public TripGroupAdapter(final Context context, final List<TripGroup> groups, Query query) {
  13. mContext = context;
  14. mGroups = groups;
  15. mQuery = query;
  16. }
  17.  
  18. public void setGroups(final List<TripGroup> groups) {
  19. mGroups = groups;
  20. this.notifyDataSetChanged();
  21. }
  22.  
  23.  
  24. public void addGroup(TripGroup group) {
  25. if(mGroups == null)
  26. mGroups = new LinkedList<TripGroup>();
  27.  
  28. mGroups.add(group);
  29. this.notifyDataSetChanged();
  30. }
  31.  
  32.  
  33. @Override
  34. public boolean hasStableIds() {
  35. return true;
  36. }
  37.  
  38. @Override
  39. public int getCount() {
  40. return mGroups == null ? 0 : mGroups.size();
  41. }
  42.  
  43. @Override
  44. public TripGroup getItem(final int position) {
  45. if(getCount() == 0 || position < 0 || position >= getCount())
  46. return null;
  47. else
  48. return mGroups.get(position);
  49. }
  50.  
  51. @Override
  52. public long getItemId(final int position) {
  53. TripGroup group = getItem(position);
  54.  
  55. if(group == null)
  56. return -1;
  57. else
  58. return group.getId();
  59. }
  60.  
  61. @Override
  62. public View getView(int position, View convertView, ViewGroup parent) {
  63. if(convertView == null) {
  64. convertView = new TripListItemView(mContext);
  65. }
  66.  
  67. TripListItemView tripView = (TripListItemView) convertView;
  68. tripView.setBackgroundResource(R.drawable.selector_trip_result_card);
  69. tripView.set(mGroups.get(position), mQuery, mCache);
  70.  
  71. return tripView;
  72. }
  73.  
  74. public void setQuery(final Query query) {
  75. mQuery = query;
  76. notifyDataSetChanged();
  77. }
  78.  
  79. @Override
  80. public void notifyDataSetChanged() {
  81.  
  82. super.notifyDataSetChanged();
  83. }
  84.  
  85.  
  86. }
  87.  
  88. getActivity().runOnUiThread(new Runnable() {
  89. @Override
  90. public void run() {
  91. mTripGroupAdapter.setGroups(tripGroupsList);
  92. }
  93. });
  94.  
  95. registerDataSetObserver(DataSetObserver observer)
  96. unregisterDataSetObserver(DataSetObserver observer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement