private void update() {
    removeAllViews();

    Adapter adapter = getAdapter();
    if (adapter != null) {
      if (valid && previousItems.size() != adapter.getCount()) {
        throw new ArrayIndexOutOfBoundsException(
            "view is valid but adapter.getCount() has changed from "
                + previousItems.size()
                + " to "
                + adapter.getCount());
      }

      List<Object> newItems = new ArrayList<Object>();
      for (int i = 0; i < adapter.getCount(); i++) {
        newItems.add(adapter.getItem(i));
        addView(adapter.getView(i, null, realAdapterView));
      }

      if (valid && !newItems.equals(previousItems)) {
        throw new RuntimeException(
            "view is valid but current items <"
                + newItems
                + "> don't match previous items <"
                + previousItems
                + ">");
      }
      previousItems = newItems;
    }
  }
 private boolean walkTree(View view, Condition<TextView> condition) {
   if (view instanceof TextView) {
     if (condition.matches((TextView) view)) {
       return true;
     }
   } else if (view instanceof AdapterView) {
     Adapter adapter = ((AdapterView) view).getAdapter();
     for (int i = 0; i < adapter.getCount(); i++) {
       View adapterView = adapter.getView(i, null, null);
       if (walkTree(adapterView, condition)) {
         return true;
       }
     }
   } else if (view instanceof ViewGroup) {
     ViewGroup viewGroup = (ViewGroup) view;
     for (int i = 0; i < viewGroup.getChildCount(); i++) {
       View childView = viewGroup.getChildAt(i);
       if (childView instanceof ViewGroup) {
         if (walkTree(childView, condition)) {
           return true;
         }
       }
     }
   }
   return false;
 }
 private void layoutChildren(int startingIndex, int adapterCount) {
   while (startingIndex < Math.min(adapterCount, MAX_VISIBLE)) {
     View newUnderChild = mAdapter.getView(startingIndex, null, this);
     if (newUnderChild.getVisibility() != GONE) {
       makeAndAddView(newUnderChild);
       LAST_OBJECT_IN_STACK = startingIndex;
     }
     startingIndex++;
   }
 }
  private View getOrCreateChild(int index) {
    View v = mChildViews.get(index);
    if (v == null) {
      v = mAdapter.getView(index, getCached(), this);
      addAndMeasureChild(index, v);
    }
    onChildSetup(index, v);

    return v;
  }
  private View getOrCreateChild(int i) {
    View v = mChildViews.get(i);
    if (v == null) {
      v = mAdapter.getView(i, getCached(), this);
      addAndMeasureChild(i, v);
      onChildSetup(i, v);
      onScaleChild(v, mScale);
    }

    return v;
  }
  private View makeAndAddView(int position, int offset, int x, boolean fromLeft) {

    View child;

    if (!mDataChanged) {
      child = mRecycler.remove();
      if (child != null) {
        child = mAdapter.getView(position, child, this);
        setUpChild(child, offset, x, fromLeft);
        return child;
      }
    }

    // Nothing found in the recycler -- ask the adapter for a view
    child = mAdapter.getView(position, null, this);

    // Position the view
    setUpChild(child, offset, x, fromLeft);

    return child;
  }
  private View viewFromAdapter(int position, boolean addToTop) {
    Assert.assertNotNull(adapter);

    View releasedView = releasedViews.isEmpty() ? null : releasedViews.removeFirst();

    View view = adapter.getView(position, releasedView, this);
    if (releasedView != null && view != releasedView) {
      addReleasedView(releasedView);
    }

    setupAdapterView(view, addToTop, view == releasedView);
    return view;
  }
Beispiel #8
0
  public void setAdapter(Adapter adapter) {
    this.adapter = adapter;
    adapter.registerDataSetObserver(adapterObserver);

    // setViewsFromAdapter(adapter);

    this.removeAllViews();
    for (int i = 0; i < adapter.getCount(); i++) {
      View temp_view = adapter.getView(i, null, null);
      TextView temp_txt = (TextView) temp_view.findViewById(R.id.gridsearch_text);

      quilt.addPatch(temp_view);
    }
  }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      int sectionnum = 0;
      for (Object section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        if (position == 0) return headers.getView(sectionnum, convertView, parent);
        if (position < size) return adapter.getView(position - 1, convertView, parent);

        position -= size;
        sectionnum++;
      }
      return null;
    }
  // @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    int sectionnum = 0;
    for (Object section : this.sections.keySet()) {
      Adapter adapter = sections.get(section);
      int size = adapter.getCount() + 1;

      // check if position inside this section
      if (position == 0) return headers.getView(sectionnum, convertView, parent);
      if (position < size) return adapter.getView(position - 1, convertView, parent);

      // otherwise jump into next section
      position -= size;
      sectionnum++;
    }
    return null;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    int sectionnum = 0;
    for (Object section : this.sections.keySet()) {
      Adapter adapter = sections.get(section);
      int size = adapter.getCount() + 1;

      // The second argument is null because if it were convertView, things crash.
      if (position == 0) return headers.getView(sectionnum, null, parent);
      if (position < size) return adapter.getView(position - 1, null, parent);

      // otherwise jump into next section
      position -= size;
      sectionnum++;
    }
    return null;
  }
Beispiel #12
0
 private View makeAndAddView(int position, boolean addToEnd) {
   View convertView = getRecycledView();
   View view = mAdapter.getView(position, convertView, this);
   if (view != convertView) {
     mRecycledViews.add(convertView);
   }
   ViewGroup.LayoutParams p = view.getLayoutParams();
   if (p == null) {
     p =
         new AbsListView.LayoutParams(
             ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
   }
   if (view == convertView) {
     attachViewToParent(view, (addToEnd ? -1 : 0), p);
   } else {
     addViewInLayout(view, (addToEnd ? -1 : 0), p, true);
   }
   return view;
 }
Beispiel #13
0
  /** {@inheritDoc} */
  @Override
  public View getView(int position, final View convertView, final ViewGroup parent) {
    int sectionnum = 0;
    for (final Object section : mSections.keySet()) {
      final Adapter adapter = mSections.get(section);
      final int size = adapter.getCount() + 1;

      // check if position inside this section
      if (position == 0) {
        return mHeaders.getView(sectionnum, convertView, parent);
      }
      if (position < size) {
        return adapter.getView(position - 1, convertView, parent);
      }

      // otherwise jump into next section
      position -= size;
      sectionnum++;
    }
    return null;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    int sectionnum = 0;
    for (int i = 0; i < headers.getCount(); i++) {
      String section = headers.getItem(i);
      Adapter adapter = sections.get(section);

      // skip empty sections
      if (adapter.getCount() > 0) {
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if (position == 0) return headers.getView(sectionnum, convertView, parent);
        if (position < size) return adapter.getView(position - 1, null, parent);

        // otherwise jump into next section
        position -= size;
      }
      sectionnum++;
    }
    return null;
  }
Beispiel #15
0
 private void injectAdapter(ViewGroup viewGroup, Adapter arrayAdapter) {
   for (int i = 0; i < arrayAdapter.getCount(); i++) {
     viewGroup.addView(arrayAdapter.getView(i, null, viewGroup));
   }
 }