Android Open Source - YgnTraffic Place Adapter






From Project

Back to project page YgnTraffic.

License

The source code is released under:

GNU General Public License

If you think the Android project YgnTraffic 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 me.sh.ygntraffic.adapter;
/* w  w  w.j a  v  a 2s  .  c  o  m*/
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;
import me.sh.ygntraffic.R;
import me.sh.ygntraffic.model.Place;

/**
 * Created by SH on 16/Jun/2014.
 */
public class PlaceAdapter extends ArrayAdapter<Place> {
  private final Context mContext;
  private ArrayList<Place> places = new ArrayList<Place>();

  public PlaceAdapter(Context context, ArrayList<Place> places) {
    super(context, R.layout.place_item, places);

    this.mContext = context;
    this.places = places;
    Log.e("", "Places Size (Adapter): " + places.size());
  }

  private ViewHolder getHolder(View v) {
    ViewHolder holder = new ViewHolder(v);

    return holder;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    View vi = convertView;

    if (vi == null) {
      LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      vi = inflater.inflate(R.layout.place_item, parent, false);
      holder = getHolder(vi);
      vi.setTag(holder);
    } else {
      holder = (ViewHolder) vi.getTag();
    }

    holder.name.setText(places.get(position).getName());

    String status = places.get(position).getStatus();
    holder.status.setText(status);
    holder.status.setBackgroundColor(places.get(position).getStatusColor(mContext, status));
    holder.time.setText(places.get(position).getReportedTime());

    return vi;
  }

  static class ViewHolder {
    @InjectView(R.id.txt_name)
    TextView name;
    @InjectView(R.id.txt_status)
    TextView status;
    @InjectView(R.id.txt_time)
    TextView time;

    public ViewHolder(View view) {
      ButterKnife.inject(this, view);
    }
  }
}




Java Source Code List

me.sh.ygntraffic.adapter.PagerAdapter.java
me.sh.ygntraffic.adapter.PlaceAdapter.java
me.sh.ygntraffic.base.BaseActivity.java
me.sh.ygntraffic.base.BaseFragment.java
me.sh.ygntraffic.fragment.MyPlaceFragment.java
me.sh.ygntraffic.fragment.TrafficFragment.java
me.sh.ygntraffic.model.Place.java
me.sh.ygntraffic.ui.DetailActivity.java
me.sh.ygntraffic.ui.MainActivity.java
me.sh.ygntraffic.util.Constants.java
me.sh.ygntraffic.util.NetUtil.java