Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TripGroupAdapter extends BaseAdapter {
- private static final String TAG = LogUtils.makeTag(TripGroupAdapter.class);
- private Context mContext;
- private List<TripGroup> mGroups;
- private Query mQuery;
- public TripGroupAdapter(final Context context, final List<TripGroup> groups, Query query) {
- mContext = context;
- mGroups = groups;
- mQuery = query;
- }
- public void setGroups(final List<TripGroup> groups) {
- mGroups = groups;
- this.notifyDataSetChanged();
- }
- public void addGroup(TripGroup group) {
- if(mGroups == null)
- mGroups = new LinkedList<TripGroup>();
- mGroups.add(group);
- this.notifyDataSetChanged();
- }
- @Override
- public boolean hasStableIds() {
- return true;
- }
- @Override
- public int getCount() {
- return mGroups == null ? 0 : mGroups.size();
- }
- @Override
- public TripGroup getItem(final int position) {
- if(getCount() == 0 || position < 0 || position >= getCount())
- return null;
- else
- return mGroups.get(position);
- }
- @Override
- public long getItemId(final int position) {
- TripGroup group = getItem(position);
- if(group == null)
- return -1;
- else
- return group.getId();
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- if(convertView == null) {
- convertView = new TripListItemView(mContext);
- }
- TripListItemView tripView = (TripListItemView) convertView;
- tripView.setBackgroundResource(R.drawable.selector_trip_result_card);
- tripView.set(mGroups.get(position), mQuery, mCache);
- return tripView;
- }
- public void setQuery(final Query query) {
- mQuery = query;
- notifyDataSetChanged();
- }
- @Override
- public void notifyDataSetChanged() {
- super.notifyDataSetChanged();
- }
- }
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mTripGroupAdapter.setGroups(tripGroupsList);
- }
- });
- registerDataSetObserver(DataSetObserver observer)
- unregisterDataSetObserver(DataSetObserver observer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement