下面列出了android.widget.BaseAdapter#getCount ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void setAdapter(BaseAdapter adapter) {
if (adapter != null) {
if (adapter.getCount() < this.rowNum * this.colNum) {
throw new IllegalArgumentException("The view count of adapter is less than this gridview's items");
}
this.removeAllViews();
for (int y = 0; y < rowNum; ++y) {
TableRow row = new TableRow(context);
row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
for (int x = 0; x < colNum; ++x) {
View view = adapter.getView(y * colNum + x, this, row);
row.addView(view, new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
}
this.addView(row);
}
}
this.adapter = adapter;
}
/**
* 设置适配器
* @param adapter
*/
public void setAdapter(BaseAdapter adapter) throws NumberOverFlowException {
this.adapter = adapter;
if (adapter.getCount() > MAX_NUM) {
throw new NumberOverFlowException(adapter.getCount());
}
adapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
super.onChanged();
onDataSetChanged();
}
@Override
public void onInvalidated() {
super.onInvalidated();
onDataSetChanged();
}
});
initChild();
}
public void updateContactsList() {
if (null == mIndexValueLv) {
return;
}
BaseAdapter contactsAdapter = (BaseAdapter) mIndexValueLv.getAdapter();
if (null != contactsAdapter) {
contactsAdapter.notifyDataSetChanged();
if (contactsAdapter.getCount() > 0) {
} else {
}
}
}
public void refreshContactsLv() {
if (null == mContactsLv) {
return;
}
ViewUtil.hideView(mContactsIndexView);
BaseAdapter contactsAdapter = (BaseAdapter) mContactsLv.getAdapter();
if (null != contactsAdapter) {
contactsAdapter.notifyDataSetChanged();
if (contactsAdapter.getCount() > 0) {
ViewUtil.showView(mContactsLv);
ViewUtil.hideView(mSearchResultPromptTv);
} else {
ViewUtil.hideView(mContactsLv);
ViewUtil.showView(mSearchResultPromptTv);
}
}
}
private void refreshT9SearchGv() {
if (null == mT9SearchGv) {
return;
}
BaseAdapter baseAdapter = (BaseAdapter) mT9SearchGv.getAdapter();
Log.i(TAG, "getCount"+baseAdapter.getCount()+"");
if (null != baseAdapter) {
baseAdapter.notifyDataSetChanged();
if (baseAdapter.getCount() > 0) {
ViewUtil.showView(mT9SearchGv);
ViewUtil.hideView(mSearchResultPromptTv);
} else {
ViewUtil.hideView(mT9SearchGv);
ViewUtil.showView(mSearchResultPromptTv);
}
}
}
private void refreshQwertySearchGv() {
if (null == mQwertySearchGv) {
return;
}
BaseAdapter baseAdapter = (BaseAdapter) mQwertySearchGv.getAdapter();
Log.i(TAG, "getCount"+baseAdapter.getCount()+"");
if (null != baseAdapter) {
baseAdapter.notifyDataSetChanged();
if (baseAdapter.getCount() > 0) {
ViewUtil.showView(mQwertySearchGv);
ViewUtil.hideView(mSearchResultPromptTv);
} else {
ViewUtil.hideView(mQwertySearchGv);
ViewUtil.showView(mSearchResultPromptTv);
}
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
BaseAdapter adapter = AdapterUtil.getAdapter(parent.getAdapter());
if (adapter == null || position >= adapter.getCount()) {
return;
}
User user = (User)adapter.getItem(position);
if (user == null) {
return;
}
Intent intent = new Intent();
intent.putExtra("USER", user);
intent.setClass(parent.getContext(), ProfileActivity.class);
context.startActivity(intent);
}
@Thunk void populateWallpapersFromAdapter(ViewGroup parent, BaseAdapter adapter,
boolean addLongPressHandler) {
for (int i = 0; i < adapter.getCount(); i++) {
FrameLayout thumbnail = (FrameLayout) adapter.getView(i, null, parent);
parent.addView(thumbnail, i);
WallpaperTileInfo info = (WallpaperTileInfo) adapter.getItem(i);
thumbnail.setTag(info);
info.setView(thumbnail);
if (addLongPressHandler) {
addLongPressHandler(thumbnail);
}
thumbnail.setOnClickListener(mThumbnailOnClickListener);
}
}
private void populateWallpapersFromAdapter(ViewGroup parent, BaseAdapter adapter,
boolean addLongPressHandler) {
for (int i = 0; i < adapter.getCount(); i++) {
FrameLayout thumbnail = (FrameLayout) adapter.getView(i, null, parent);
parent.addView(thumbnail, i);
WallpaperTileInfo info = (WallpaperTileInfo) adapter.getItem(i);
thumbnail.setTag(info);
info.setView(thumbnail);
if (addLongPressHandler) {
addLongPressHandler(thumbnail);
}
thumbnail.setOnClickListener(mThumbnailOnClickListener);
}
}
private void populateWallpapersFromAdapter(ViewGroup parent, BaseAdapter adapter,
boolean addLongPressHandler) {
for (int i = 0; i < adapter.getCount(); i++) {
FrameLayout thumbnail = (FrameLayout) adapter.getView(i, null, parent);
parent.addView(thumbnail, i);
WallpaperTileInfo info = (WallpaperTileInfo) adapter.getItem(i);
thumbnail.setTag(info);
info.setView(thumbnail);
if (addLongPressHandler) {
addLongPressHandler(thumbnail);
}
thumbnail.setOnClickListener(mThumbnailOnClickListener);
}
}
public ArticleCollectionPagerAdapter(Application app, BaseAdapter data, ToBlob toBlob, FragmentManager fm) {
super(fm);
this.app = app;
this.data = data;
this.count = data.getCount();
this.observer = new DataSetObserver(){
@Override
public void onChanged() {
count = ArticleCollectionPagerAdapter.this.data.getCount();
notifyDataSetChanged();
}
};
data.registerDataSetObserver(observer);
this.toBlob = toBlob;
}
/**
* Constructs a {@linkplain CircularListAdapter}.
*
* @param listAdapter A {@link ListAdapter} that has to behave circular.
*/
public CircularListAdapter(BaseAdapter listAdapter) {
if(listAdapter == null) {
throw new IllegalArgumentException("listAdapter cannot be null.");
}
this.mListAdapter = listAdapter;
this.mListAdapterCount = listAdapter.getCount();
}