Android Open Source - Android-Counter-Application Counter Adapter






From Project

Back to project page Android-Counter-Application.

License

The source code is released under:

GNU General Public License

If you think the Android project Android-Counter-Application 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 ca.ualberta.cs.artem_counter;
//from  www . j a va2 s .co m
import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

//This is a custom adapter, used to display counter objects in a list in the CounterListActivity
public class CounterAdapter extends BaseAdapter {

  private Context context;
  private static ArrayList<Counter> listCounter;

  public CounterAdapter(Context context, ArrayList<Counter> list) {
    this.context = context;
    CounterAdapter.listCounter = list;
  }
  @Override
  public int getCount() {
    return listCounter.size();
  }
  @Override
  public Object getItem(int position) {
    return listCounter.get(position);
  }
  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    Counter item = listCounter.get(position);

    if (convertView == null) {
      LayoutInflater inflater = (LayoutInflater) context
          .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = inflater.inflate(R.layout.list_counter_item, null);
    }

    TextView name = (TextView) convertView.findViewById(R.id.CounterTitle);
    name.setText(item.getName());

    TextView value = (TextView) convertView.findViewById(R.id.CounterValue);
    value.setText(String.valueOf(item.getCount()));

    return convertView;
  }
}




Java Source Code List

ca.ualberta.cs.artem_counter.CounterAdapter.java
ca.ualberta.cs.artem_counter.CounterHistoryActivity.java
ca.ualberta.cs.artem_counter.CounterHistoryFragment.java
ca.ualberta.cs.artem_counter.CounterHistory.java
ca.ualberta.cs.artem_counter.CounterListActivity.java
ca.ualberta.cs.artem_counter.CounterList.java
ca.ualberta.cs.artem_counter.Counter.java