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

The following examples show how to use android.widget.AdapterView#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: MDRootLayout.java    From talk-android with MIT License 6 votes vote down vote up
private static boolean canAdapterViewScroll(AdapterView lv) {
    /* Force it to layout it's children */
    if (lv.getLastVisiblePosition() == -1)
        return false;

    /* We can scroll if the first or last item is not visible */
    boolean firstItemVisible = lv.getFirstVisiblePosition() == 0;
    boolean lastItemVisible = lv.getLastVisiblePosition() == lv.getCount() - 1;

    if (firstItemVisible && lastItemVisible && lv.getChildCount() > 0) {
        /* Or the first item's top is above or own top */
        if (lv.getChildAt(0).getTop() < lv.getPaddingTop())
            return true;
        /* or the last item's bottom is beyond our own bottom */
        return lv.getChildAt(lv.getChildCount() - 1).getBottom() >
                lv.getHeight() - lv.getPaddingBottom();
    }

    return true;
}
 
Example 2
Source File: PhotoSelectorActivity.java    From umeng_community_android with MIT License 6 votes vote down vote up
/** 相册列表点击事件 */
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
        long id) {
    AlbumModel current = (AlbumModel) parent.getItemAtPosition(position);
    for (int i = 0; i < parent.getCount(); i++) {
        AlbumModel album = (AlbumModel) parent.getItemAtPosition(i);
        if (i == position) {
            album.setCheck(true);
        }
        else {
            album.setCheck(false);
        }
    }
    albumAdapter.notifyDataSetChanged();
    hideAlbum();
    tvAlbum.setText(current.getName());

    if (current.getName().equals(RECCENT_PHOTO)) {
        photoSelectorDomain.getReccent(reccentListener);
    } else {
        photoSelectorDomain.getAlbum(current.getName(), reccentListener); // 获取选中相册的照片
    }
}
 
Example 3
Source File: EndlessListView.java    From fanfouapp-opensource with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemClick(final AdapterView<?> parent, final View view,
        final int position, final long id) {
    if (AppContext.DEBUG) {
        log("onItemClick() list.size=" + parent.getCount()
                + " adapter.size=" + parent.getAdapter().getCount()
                + " position=" + position + " id=" + id);
    }
    final Object o = parent.getItemAtPosition(position);
    if (o == null) {
        if (position == 0) {
            setRefreshing();
        } else if (position == (parent.getCount() - 1)) {
            setLoading();
        }
    } else {
        if (this.mOnRefreshListener != null) {
            this.mOnRefreshListener.onItemClick(this, view, position);
        }
    }
}
 
Example 4
Source File: EndlessListViewNoHeader.java    From fanfouapp-opensource with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemClick(final AdapterView<?> parent, final View view,
        final int position, final long id) {
    if (AppContext.DEBUG) {
        log("onItemClick() list.size=" + parent.getCount()
                + " adapter.size=" + parent.getAdapter().getCount()
                + " position=" + position + " id=" + id);
    }
    final Object o = parent.getItemAtPosition(position);
    if (o == null) {
        if (position == (parent.getCount() - 1)) {
            setLoading();
        }
    } else {
        if (this.mOnRefreshListener != null) {
            this.mOnRefreshListener.onItemClick(this, position);
        }
    }
}
 
Example 5
Source File: PostItemsListFragment.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    if (parent.getCount() > position) {
        ChanBoard b = (ChanBoard) parent.getItemAtPosition(position);
        boardName = b.getName();
        boardTitle = b.getTitle();

        refreshBoard(true);
    }
}
 
Example 6
Source File: ListViewHandler.java    From CommonPullToRefresh with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemSelected(AdapterView<?> listView, View view, int position, long id) {
    if (listView.getLastVisiblePosition() + 1 == listView.getCount()) {// 如果滚动到最后一行
        if (onScrollBottomListener != null) {
            onScrollBottomListener.onScorllBootom();
        }
    }
}
 
Example 7
Source File: GridViewHandler.java    From CommonPullToRefresh with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
    if (adapterView.getLastVisiblePosition() + 1 == adapterView.getCount()) {// 如果滚动到最后一行
        if (onScrollBottomListener != null) {
            onScrollBottomListener.onScorllBootom();
        }
    }
}
 
Example 8
Source File: AbsRefreshLayout.java    From NestRefreshLayout with MIT License 5 votes vote down vote up
private boolean canListScroll(int direction) {
    AdapterView<?> absListView = (AdapterView<?>) mTargetView;
    final int itemCount = absListView.getCount();
    final int childCount = absListView.getChildCount();
    final int firstPosition = absListView.getFirstVisiblePosition();
    final int lastPosition = firstPosition + childCount;

    if (itemCount == 0) {
        return false;
    }
    if (direction > 0) {
        // Are we already showing the entire last item?
        if (lastPosition >= itemCount) {
            final View lastView = absListView.getChildAt(childCount - 1);
            if (lastView != null
                    && lastView.getBottom() >= mTargetView.getHeight()) {
                return false;
            }
        }
    } else if (direction < 0) {
        // Are we already showing the entire first item?
        if (firstPosition <= 0) {
            final View firstView = absListView.getChildAt(0);
            if (firstView != null && firstView.getTop() >= 0) {
                return false;
            }
        }
    }
    return true;
}
 
Example 9
Source File: AdapterViewProtocols.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<AdaptedData> getDataInAdapterView(AdapterView<? extends Adapter> adapterView) {
  List<AdaptedData> datas = Lists.newArrayList();
  for (int i = 0; i < adapterView.getCount(); i++) {
    int position = i;
    Object dataAtPosition = adapterView.getItemAtPosition(position);
    datas.add(
        new AdaptedData.Builder()
            .withDataFunction(new StandardDataFunction(dataAtPosition, position))
            .withOpaqueToken(position)
            .build());
  }
  return datas;
}
 
Example 10
Source File: MainActivity.java    From Pimp_my_Z1 with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    for (int i = 0; i < parent.getCount(); i++)
        view.setBackground(getColouredTouchFeedback());
    selectItem(position);
}
 
Example 11
Source File: HomeACTIVITY.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    selectItem(position);
    if(!isActivity(position)){
     	for(int i=0;i<parent.getCount();i++){
      View v=parent.getChildAt(i);
      if (position == i) {
          v.setBackgroundColor(Color.GRAY);
      } else {
          v.setBackgroundColor(Color.TRANSPARENT);
      }
  }
    }
    }
 
Example 12
Source File: SudokuBoardCustomThemePreferenceGroup.java    From opensudoku with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (position == parent.getCount() - 1) {
        showCreateFromSingleColorDialog();
    } else if (position == parent.getCount() - 2) {
        showCopyFromExistingThemeDialog();
    } else if (position == 0) {
        SwitchPreference preference = (SwitchPreference) getPreference(position);
        preference.setChecked(!preference.isChecked());
    } else {
        ((ColorPickerPreference) getPreference(position)).onPreferenceClick(null);
    }
}