Java Code Examples for android.widget.Adapter#getCount()

The following examples show how to use android.widget.Adapter#getCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeparatedListAdapter.java    From shortyz with GNU General Public License v3.0 6 votes vote down vote up
public int getItemViewType(int position) {
    for (Adapter adapter : this.sections) {
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if (position == 0) {
            return TYPE_SECTION_HEADER;
        }

        if (position < size) {
            return 1;
        }

        // otherwise jump into next section
        position -= size;

        //type += adapter.getViewTypeCount();
    }

    return -1;
}
 
Example 2
Source File: SeparatedListAdapter.java    From sensordatacollector with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getItemViewType(int position)
{
    int type = 1;
    for(String section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if(position == 0)
            return TYPE_SECTION_HEADER;
        if(position < size)
            return type + adapter.getItemViewType(position - 1);

        // otherwise jump into next section
        position -= size;
        type += adapter.getViewTypeCount();
    }
    return -1;
}
 
Example 3
Source File: SeparatedListAdapter.java    From shortyz with GNU General Public License v3.0 6 votes vote down vote up
public View getView(int i, View view, ViewGroup group) {
    int sectionnum = 0;

    for (Adapter adapter : this.sections) {
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if (i == 0) {
            return headers.getView(sectionnum, view, group);
        }

        if (i < size) {
            return adapter.getView(i - 1, view, group);
        }

        // otherwise jump into next section
        i -= size;
        sectionnum++;
    }

    return null;
}
 
Example 4
Source File: SeparatedListAdapter.java    From RoMote with Apache License 2.0 6 votes vote down vote up
public int getItemViewType(int position) {
    int type = 1;
    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 TYPE_SECTION_HEADER;
        if(position < size) return type + adapter.getItemViewType(position - 1);

        // otherwise jump into next section
        position -= size;
        type += adapter.getViewTypeCount();
    }
    return -1;
}
 
Example 5
Source File: AdapterViewTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
private static Matcher<View> withAdaptedData(final Matcher<Object> dataMatcher) {
  return new TypeSafeMatcher<View>() {

    @Override
    public void describeTo(Description description) {
      description.appendText("with class name: ");
      dataMatcher.describeTo(description);
    }

    @Override
    public boolean matchesSafely(View view) {
      if (!(view instanceof AdapterView)) {
        return false;
      }
      @SuppressWarnings("rawtypes")
      Adapter adapter = ((AdapterView) view).getAdapter();
      for (int i = 0; i < adapter.getCount(); i++) {
        if (dataMatcher.matches(adapter.getItem(i))) {
          return true;
        }
      }
      return false;
    }
  };
}
 
Example 6
Source File: FlipViewController.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public void setAdapter(Adapter adapter, int initialPosition) {
  if (this.adapter != null) {
    this.adapter.unregisterDataSetObserver(adapterDataObserver);
  }

  Assert.assertNotNull("adapter should not be null", adapter);

  this.adapter = adapter;
  adapterDataCount = adapter.getCount();

  adapterDataObserver = new MyDataSetObserver();
  this.adapter.registerDataSetObserver(adapterDataObserver);
  if (adapterDataCount > 0) {
    setSelection(initialPosition);
  }
}
 
Example 7
Source File: SeparatedListAdapter.java    From BatteryFu with GNU General Public License v2.0 6 votes vote down vote up
@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);
        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;
}
 
Example 8
Source File: SectionListAdapter.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
public int indexOf(Object object)
{
    int idx = 0;
    for (final Map.Entry<String,Adapter> entry : sectionMap.entrySet())
    {
        final Adapter adapter = entry.getValue();
        
        if (object.equals(entry.getKey()))
            return idx;
        
        for (int i = 0; i < adapter.getCount(); i++)
        {
            if (object.equals(adapter.getItem(i)))
                return idx + (hasSectionHeader ? 1 : 0) + i;
        }
        
        idx += adapter.getCount() + (hasSectionHeader ? 1 : 0);
    }
    return -1;
}
 
Example 9
Source File: MultiSelectionUtil.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private void tryRestoreInstanceState(HashSet<Long> idsToCheckOnRestore) {
    if (idsToCheckOnRestore == null || mListView.getAdapter() == null) {
        return;
    }
    boolean idsFound = false;
    Adapter adapter = mListView.getAdapter();
    for (int pos = adapter.getCount() - 1; pos >= 0; pos--) {
        if (idsToCheckOnRestore.contains(adapter.getItemId(pos))) {
            idsFound = true;
            if (mItemsToCheck == null) {
                mItemsToCheck = new HashSet<Pair<Integer, Long>>();
            }
            mItemsToCheck.add(new Pair<Integer, Long>(pos, adapter.getItemId(pos)));
        }
    }
    if (idsFound) {
        // We found some IDs that were checked. Let's now restore the multi-selection
        // state.
        mActionMode = mActivity.startSupportActionMode(mCallbacks);
    }
}
 
Example 10
Source File: SectionListAdapter.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, final View convertView, final ViewGroup parent)
{
    
    int sectionNum = 0;
    
    for (final String sectionName : sectionMap.keySet())
    {
        final Adapter adapter = sectionMap.get(sectionName);
        
        final int size = adapter.getCount() + (hasSectionHeader ? 1 : 0);
        
        if (position == 0 && hasSectionHeader)
            return sectionAdapter.getView(sectionNum, convertView, parent);
        
        if (position < size)
            return adapter.getView(position - 1, convertView, parent);
        
        position -= size;
        sectionNum++;
    }
    
    return null;
}
 
Example 11
Source File: SeparatedListAdapter.java    From padland with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 12
Source File: SeparatedListAdapter.java    From BatteryFu with GNU General Public License v2.0 5 votes vote down vote up
public int getCount() {
    // total together all sections, plus one for each section header
    int total = 0;
    for (Adapter adapter : this.sections.values())
        total += adapter.getCount() + 1;
    return total;
}
 
Example 13
Source File: AppPickerActivity.java    From zxingfragmentlib with Apache License 2.0 5 votes vote down vote up
@Override
protected void onListItemClick(ListView l, View view, int position, long id) {
  Adapter adapter = getListAdapter();
  if (position >= 0 && position < adapter.getCount()) {
    String packageName = ((AppInfo) adapter.getItem(position)).getPackageName();
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Browser.BookmarkColumns.URL, "market://details?id=" + packageName);
    setResult(RESULT_OK, intent);
  } else {
    setResult(RESULT_CANCELED);      
  }
  finish();
}
 
Example 14
Source File: InternalApisFragment.java    From line-sdk-android with Apache License 2.0 5 votes vote down vote up
private final List<String> getSelectedReceiverIDs(final ListView listView) {
    final List<String> receiverIDs = new ArrayList<>();

    final Adapter adapter = listView.getAdapter();
    final SparseBooleanArray checkedItems = listView.getCheckedItemPositions();
    for (int i = 0; i < adapter.getCount(); i++) {
        if (checkedItems.get(i)) {
            receiverIDs.add(((Receiver) adapter.getItem(i)).id);
        }
    }

    return receiverIDs;
}
 
Example 15
Source File: AppPickerActivity.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
protected void onListItemClick(ListView l, View view, int position, long id) {
  Adapter adapter = getListAdapter();
  if (position >= 0 && position < adapter.getCount()) {
    String packageName = ((AppInfo) adapter.getItem(position)).getPackageName();
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra("url", "market://details?id=" + packageName);
    setResult(RESULT_OK, intent);
  } else {
    setResult(RESULT_CANCELED);      
  }
  finish();
}
 
Example 16
Source File: SeparatedListAdapter.java    From Makeblock-App-For-Android with MIT License 5 votes vote down vote up
public int getCount() {
    // total together all sections, plus one for each section header
    int total = 0;
    for (Adapter adapter : this.sections.values())
        total += adapter.getCount() + 1;
    return total;
}
 
Example 17
Source File: SeparatedListAdapter.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
public int getCount() {
    // total together all sections, plus one for each section header
    int total = 0;

    for (Adapter adapter : this.sections)
        total += (adapter.getCount() + 1);

    return total;
}
 
Example 18
Source File: SeparatedListAdapter.java    From padland with Apache License 2.0 5 votes vote down vote up
public Object getItem(int position) {
    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 section;
        if(position < size) return adapter.getItem(position - 1);

        // otherwise jump into next section
        position -= size;
    }
    return null;
}
 
Example 19
Source File: PullToRefreshList.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 判断最后一个child是否完全显示出来
 * 
 * @return true完全显示出来,否则false
 */
private boolean isLastItemVisible() {
    final Adapter adapter = mfakeListView.getAdapter();

    if (null == adapter || adapter.isEmpty()) {
        return true;
    }

    final int lastItemPosition = adapter.getCount() - 1;
    final int lastVisiblePosition = mfakeListView.getLastVisiblePosition();

    /**
     * This check should really just be: lastVisiblePosition ==
     * lastItemPosition, but ListView internally uses a FooterView which
     * messes the positions up. For me we'll just subtract one to account
     * for it and rely on the inner condition which checks getBottom().
     */
    if (lastVisiblePosition >= lastItemPosition - 1) {
        final int childIndex = lastVisiblePosition
                - mfakeListView.getFirstVisiblePosition();
        final int childCount = mfakeListView.getChildCount();
        final int index = Math.min(childIndex, childCount - 1);
        final View lastVisibleChild = mfakeListView.getChildAt(index);
        if (lastVisibleChild != null) {
            return lastVisibleChild.getBottom() <= mfakeListView
                    .getBottom();
        }
    }

    return false;
}
 
Example 20
Source File: AdapterView.java    From android-tv-launcher with MIT License 5 votes vote down vote up
private boolean isScrollableForAccessibility() {
	Adapter localAdapter = getAdapter();
	if (localAdapter != null) {
		int i = localAdapter.getCount();
		return (i > 0) && ((getFirstVisiblePosition() > 0) || (getLastVisiblePosition() < i - 1));
	}
	return false;
}