Android Open Source - ponyville-live-android Network Variance Adapter

From Project

Back to project page ponyville-live-android.


The source code is released under:

Apache License

If you think the Android project ponyville-live-android 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

/*from ww w.j  a v  a  2  s  . c o m*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import static butterknife.ButterKnife.findById;

class NetworkVarianceAdapter extends BindableAdapter<Integer> {
  private static final int[] VALUES = {
      20, 40, 60

  public static int getPositionForValue(int value) {
    for (int i = 0; i < VALUES.length; i++) {
      if (VALUES[i] == value) {
        return i;
    return 1; // Default to 40% if something changes.

  NetworkVarianceAdapter(Context context) {

  public int getCount() {
    return VALUES.length;

  public Integer getItem(int position) {
    return VALUES[position];

  public long getItemId(int position) {
    return position;

  public View newView(LayoutInflater inflater, int position, ViewGroup container) {
    return inflater.inflate(android.R.layout.simple_spinner_item, container, false);

  public void bindView(Integer item, int position, View view) {
    TextView tv = findById(view,;
    tv.setText("" + item + "%");

  public View newDropDownView(LayoutInflater inflater, int position, ViewGroup container) {
    return inflater.inflate(android.R.layout.simple_spinner_dropdown_item, container, false);

Java Source Code List