Android Open Source - SeeKampf Custom Adapter






From Project

Back to project page SeeKampf.

License

The source code is released under:

GNU General Public License

If you think the Android project SeeKampf listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.avedo.seekampf.core;
//from   w  ww  .j  a  v a2  s  . co m
import java.util.ArrayList;
import java.util.Arrays;

import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import net.avedo.seekampf.models.BaseModel;

public class CustomAdapter<T extends BaseModel> extends BaseAdapter {
  protected ArrayList<T> items;
  protected Context context;
  protected Resources res;
  protected int resId;

  protected boolean notifyOnChange = true;

  public CustomAdapter(Context context, int resId, T[] items) {
    this.items = new ArrayList<T>();
    this.items.addAll(Arrays.asList(items));
    this.context = context;
    this.resId = resId;
    this.res = context.getResources();
  }

  @Override
  public int getCount() {
        return this.items.size();
  }

  @Override
  public T getItem(int position) {
        return this.items.get(position);
  }

  @Override
  public long getItemId(int position) {
        return getItem(position).getId();
    }

  public void add(T item) {
    this.items.add(item);

    if (this.notifyOnChange) {
      notifyDataSetChanged();
    }
  }

  public void addAll(T[] items) {
    this.items.addAll(Arrays.asList(items));

    if (this.notifyOnChange) {
      notifyDataSetChanged();
    }
  }

  public void insert(T item, int index) {
    this.items.add(index, item);

    if (this.notifyOnChange) {
      notifyDataSetChanged();
    }
  }

  public void remove(T item) {
    this.items.remove(item);

    if (this.notifyOnChange) {
      notifyDataSetChanged();
    }
  }

  public void clear() {
    this.items.clear();

    if (this.notifyOnChange) {
      notifyDataSetChanged();
    }
  }

  public Context getContext() {
    return this.context;
  }

  public void setNotifyOnChange(boolean notifyOnChange) {
    this.notifyOnChange = notifyOnChange;
  }

  @Override
  public void notifyDataSetChanged() {
    super.notifyDataSetChanged();
    this.notifyOnChange = true;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    return convertView;
  }
}




Java Source Code List

net.avedo.seekampf.BuildConfig.java
net.avedo.seekampf.core.ChangeLog.java
net.avedo.seekampf.core.CustomAdapter.java
net.avedo.seekampf.core.MainActivity.java
net.avedo.seekampf.core.OceanView.java
net.avedo.seekampf.core.OverScrollerCompat.java
net.avedo.seekampf.core.RestDetailsActivity.java
net.avedo.seekampf.core.ScaleGestureDetectorCompat.java
net.avedo.seekampf.core.VolleyActivity.java
net.avedo.seekampf.core.Zoomer.java
net.avedo.seekampf.fragments.AboutFragment.java
net.avedo.seekampf.fragments.AllianceListFragment.java
net.avedo.seekampf.fragments.AuctionListFragment.java
net.avedo.seekampf.fragments.HomeDetailsFragment.java
net.avedo.seekampf.fragments.HomeFragment.java
net.avedo.seekampf.fragments.IslandDetailsFragment.java
net.avedo.seekampf.fragments.IslandListFragment.java
net.avedo.seekampf.fragments.MessageDetailsFragment.java
net.avedo.seekampf.fragments.MessageListFragment.java
net.avedo.seekampf.fragments.OceanFragment.java
net.avedo.seekampf.fragments.PlayerListFragment.java
net.avedo.seekampf.fragments.RestDetailsFragment.java
net.avedo.seekampf.fragments.RestListFragment.java
net.avedo.seekampf.fragments.SettingsFragment.java
net.avedo.seekampf.models.Alliance.java
net.avedo.seekampf.models.Auction.java
net.avedo.seekampf.models.BaseModel.java
net.avedo.seekampf.models.Island.java
net.avedo.seekampf.models.Message.java
net.avedo.seekampf.models.Player.java
net.avedo.seekampf.utils.AuthGsonRequest.java
net.avedo.seekampf.utils.Constants.java
net.avedo.seekampf.utils.Interfaces.java
net.avedo.seekampf.utils.VolleyErrorHelper.java