android.widget.ListView#getChildCount ( )源码实例Demo

下面列出了android.widget.ListView#getChildCount ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ListBuddies   文件: ListBuddiesLayout.java
private void findViewClicked(MotionEvent event, float eventY, ListView list) {
    mChildCount = list.getChildCount();
    mListViewCoords = new int[2];
    list.getLocationOnScreen(mListViewCoords);
    int x = (int) event.getRawX() - mListViewCoords[0];
    int y = (int) event.getRawY() - mListViewCoords[1];
    View child;
    for (int i = 0; i < mChildCount; i++) {
        child = list.getChildAt(i);
        child.getHitRect(mRect);
        if (mRect.contains(x, y)) {
            mDownView = child;
            mDownEventY = eventY;
            break;
        }
    }
}
 
源代码2 项目: letv   文件: TopRecommendFragment.java
private void loadImage(ListView listView) {
    if (listView != null) {
        try {
            int count = listView.getChildCount();
            for (int i = 0; i < count; i++) {
                Object tag = listView.getChildAt(i).getTag();
                if (tag != null) {
                    ViewHolder holder = (ViewHolder) tag;
                    Object t1 = holder.iv_1.getTag();
                    if (t1 != null) {
                        ImageDownloader.getInstance().download(holder.iv_1, (String) t1);
                        holder.iv_1.setTag(null);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
源代码3 项目: letv   文件: ListViewAutoScrollHelper.java
public boolean canTargetScrollVertically(int direction) {
    ListView target = this.mTarget;
    int itemCount = target.getCount();
    if (itemCount == 0) {
        return false;
    }
    int childCount = target.getChildCount();
    int firstPosition = target.getFirstVisiblePosition();
    int lastPosition = firstPosition + childCount;
    if (direction > 0) {
        if (lastPosition >= itemCount && target.getChildAt(childCount - 1).getBottom() <= target.getHeight()) {
            return false;
        }
    } else if (direction >= 0) {
        return false;
    } else {
        if (firstPosition <= 0 && target.getChildAt(0).getTop() >= 0) {
            return false;
        }
    }
    return true;
}
 
源代码4 项目: NMSAlphabetAndroidApp   文件: SettingsFragment.java
private void updatePreferences(ListView accountList){
    for(int i = 0; i < accountList.getChildCount(); i++) {
        try {
            LinearLayout rootLayout = (LinearLayout) accountList.getChildAt(i);
            RelativeLayout preferenceLayout = (RelativeLayout) rootLayout.getChildAt(1);
            TextView titleView = (TextView) preferenceLayout.getChildAt(0);
            TextView summaryView = (TextView) preferenceLayout.getChildAt(1);
            if(titleView.getText().toString().equals(getString(R.string.language))) {
                summaryView.setCompoundDrawablePadding(10);
                summaryView.setCompoundDrawablesRelativeWithIntrinsicBounds(LanguageUtil.getLanguageFlagDrawable(getActivity(),
                        LanguageUtil.getCurrentLanguageCode(getActivity())), null, null, null);
            } else if(titleView.getText().toString().equals(getString(R.string.theme))) {
                summaryView.setText(ThemeUtil.getThemePreview(getActivity(), ThemeUtil.getCurrentTheme(getActivity())));
                summaryView.setTextSize(30);
            }
        } catch (Exception e){
            e.printStackTrace();
        }
    }
}
 
源代码5 项目: zone-sdk   文件: ViewShot.java
/**
 * 截图listview
 **/
public static Bitmap getBitmapByListView(ListView listView) {
    int h = 0;
    Bitmap bitmap = null;
    // 获取listView实际高度
    for (int i = 0; i < listView.getChildCount(); i++) {
        h += listView.getChildAt(i).getHeight();
    }
    Log.d(TAG, "实际高度:" + h);
    Log.d(TAG, "list 高度:" + listView.getHeight());
    // 创建对应大小的bitmap
    bitmap = Bitmap.createBitmap(listView.getWidth(), h,
            Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);
    listView.draw(canvas);
    return bitmap;
}
 
源代码6 项目: YiBo   文件: HomePageHeaderDoubleClickListener.java
@Override
public void onDoubleClick(View v) {
       //双击事件
    Activity context = (Activity)v.getContext();
       ListView lvMicroBlog = (ListView)context.findViewById(R.id.lvMicroBlog);
       if (lvMicroBlog != null) {
     		ListAdapter adapter = lvMicroBlog.getAdapter();
		CacheAdapter<?> cacheAdapter = getCacheAdapter(adapter);
        if (cacheAdapter != null) {
            cacheAdapter.reclaim(ReclaimLevel.MODERATE);
        }
        if (lvMicroBlog.getChildCount() > 1) {
        	lvMicroBlog.setSelection(1);
        }
       }
}
 
源代码7 项目: Dashchan   文件: ThreadsPage.java
@Override
public void onImageLoadComplete(String key, Bitmap bitmap, boolean error) {
	UiManager uiManager = getUiManager();
	ThreadsAdapter adapter = getAdapter();
	ListView listView = getListView();
	for (int i = 0; i < listView.getChildCount(); i++) {
		View view = listView.getChildAt(i);
		if (adapter.isGridMode()) {
			if (view instanceof ViewGroup) {
				ViewGroup viewGroup = (ViewGroup) view;
				for (int j = 0; j < viewGroup.getChildCount(); j++) {
					View child = viewGroup.getChildAt(j);
					if (child.getVisibility() == View.VISIBLE) {
						uiManager.view().displayLoadedThumbnailsForView(child, key, bitmap, error);
					}
				}
			}
		} else {
			uiManager.view().displayLoadedThumbnailsForView(view, key, bitmap, error);
		}
	}
}
 
源代码8 项目: easy-guide-android   文件: ListViewActivity.java
public View getViewByPosition(int pos, ListView listView) {
    final int firstListItemPosition = listView.getFirstVisiblePosition();
    final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;

    if (pos < firstListItemPosition || pos > lastListItemPosition ) {
        return null;
    } else {
        final int childIndex = pos - firstListItemPosition;
        return listView.getChildAt(childIndex);
    }
}
 
源代码9 项目: soas   文件: SwipeRefreshListFragment.java
/**
 * Utility method to check whether a {@link ListView} can scroll up from it's current position.
 * Handles platform version differences, providing backwards compatible functionality where
 * needed.
 */
private static boolean canListViewScrollUp(ListView listView) {
    if (SdkUtils.hasIceCreamSandwich()) {
        // For ICS and above we can call canScrollVertically() to determine this
        return ViewCompat.canScrollVertically(listView, -1);
    } else {
        // Pre-ICS we need to manually check the first visible item and the child view's top
        // value
        return listView.getChildCount() > 0 &&
                (listView.getFirstVisiblePosition() > 0
                        || listView.getChildAt(0).getTop() < listView.getPaddingTop());
    }
}
 
源代码10 项目: aptoide-client   文件: FragmentSocialTimeline.java
private static boolean canListViewScrollUp(ListView listView) {
    if (android.os.Build.VERSION.SDK_INT >= 14) {
        // For ICS and above we can call canScrollVertically() to determine this
        return ViewCompat.canScrollVertically(listView, -1);
    } else {
        // Pre-ICS we need to manually check the first visible item and the child view's top
        // value
        return listView.getChildCount() > 0 &&
                (listView.getFirstVisiblePosition() > 0
                        || listView.getChildAt(0).getTop() < listView.getPaddingTop());
    }
}
 
源代码11 项目: flickr-uploader   文件: DrawerContentView.java
private void renderView(int position) {
	View view = gridViewsArray[position];
	if (view != null) {
		ListView listView = (ListView) view.findViewById(R.id.list_view);
		for (int i = 0; i < listView.getChildCount(); i++) {
			renderThumbView(listView.getChildAt(i));
		}
	}
}
 
/**
 * Utility method to check whether a {@link ListView} can scroll up from it's current position.
 * Handles platform version differences, providing backwards compatible functionality where
 * needed.
 */
private static boolean canListViewScrollUp(ListView listView) {
    if (android.os.Build.VERSION.SDK_INT >= 14) {
        // For ICS and above we can call canScrollVertically() to determine this
        return ViewCompat.canScrollVertically(listView, -1);
    } else {
        // Pre-ICS we need to manually check the first visible item and the child view's top
        // value
        return listView.getChildCount() > 0 &&
                (listView.getFirstVisiblePosition() > 0
                        || listView.getChildAt(0).getTop() < listView.getPaddingTop());
    }
}
 
源代码13 项目: iqra-android   文件: SearchResultsActivity.java
public View getViewByPosition(int pos, ListView listView) {
    final int firstListItemPosition = listView.getFirstVisiblePosition();
    final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;

    if (pos < firstListItemPosition || pos > lastListItemPosition) {
        return listView.getAdapter().getView(pos, null, listView);
    } else {
        final int childIndex = pos - firstListItemPosition;
        return listView.getChildAt(childIndex);
    }
}
 
@Override
public boolean canTargetScrollVertically(int direction) {
    final ListView target = mTarget;
    final int itemCount = target.getCount();
    final int childCount = target.getChildCount();
    final int firstPosition = target.getFirstVisiblePosition();
    final int lastPosition = firstPosition + childCount;

    if (direction > 0) {
        // Are we already showing the entire last item?
        if (lastPosition >= itemCount) {
            final View lastView = target.getChildAt(childCount - 1);
            if (lastView.getBottom() <= target.getHeight()) {
                return false;
            }
        }
    } else if (direction < 0) {
        // Are we already showing the entire first item?
        if (firstPosition <= 0) {
            final View firstView = target.getChildAt(0);
            if (firstView.getTop() >= 0) {
                return false;
            }
        }
    } else {
        // The behavior for direction 0 is undefined and we can return
        // whatever we want.
        return false;
    }

    return true;
}
 
源代码15 项目: a   文件: ConvertUtils.java
/**
 * 把view转化为bitmap(截图)
 * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html
 */
public static Bitmap toBitmap(View view) {
    int width = view.getWidth();
    int height = view.getHeight();
    if (view instanceof ListView) {
        height = 0;
        // 获取listView实际高度
        ListView listView = (ListView) view;
        for (int i = 0; i < listView.getChildCount(); i++) {
            height += listView.getChildAt(i).getHeight();
        }
    } else if (view instanceof ScrollView) {
        height = 0;
        // 获取scrollView实际高度
        ScrollView scrollView = (ScrollView) view;
        for (int i = 0; i < scrollView.getChildCount(); i++) {
            height += scrollView.getChildAt(i).getHeight();
        }
    }
    view.setDrawingCacheEnabled(true);
    view.clearFocus();
    view.setPressed(false);
    boolean willNotCache = view.willNotCacheDrawing();
    view.setWillNotCacheDrawing(false);
    // Reset the drawing cache background color to fully transparent for the duration of this operation
    int color = view.getDrawingCacheBackgroundColor();
    view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素)
    if (color != Color.WHITE) {
        view.destroyDrawingCache();
    }
    view.buildDrawingCache();
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap == null) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(cacheBitmap, 0, 0, null);
    canvas.save();
    canvas.restore();
    if (!bitmap.isRecycled()) {
        bitmap.recycle();
    }
    // Restore the view
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}
 
源代码16 项目: FilePicker   文件: ConvertUtils.java
/**
 * 把view转化为bitmap(截图)
 * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html
 */
public static Bitmap toBitmap(View view) {
    int width = view.getWidth();
    int height = view.getHeight();
    if (view instanceof ListView) {
        height = 0;
        // 获取listView实际高度
        ListView listView = (ListView) view;
        for (int i = 0; i < listView.getChildCount(); i++) {
            height += listView.getChildAt(i).getHeight();
        }
    } else if (view instanceof ScrollView) {
        height = 0;
        // 获取scrollView实际高度
        ScrollView scrollView = (ScrollView) view;
        for (int i = 0; i < scrollView.getChildCount(); i++) {
            height += scrollView.getChildAt(i).getHeight();
        }
    }
    view.setDrawingCacheEnabled(true);
    view.clearFocus();
    view.setPressed(false);
    boolean willNotCache = view.willNotCacheDrawing();
    view.setWillNotCacheDrawing(false);
    // Reset the drawing cache background color to fully transparent for the duration of this operation
    int color = view.getDrawingCacheBackgroundColor();
    view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素)
    if (color != Color.WHITE) {
        view.destroyDrawingCache();
    }
    view.buildDrawingCache();
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap == null) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(cacheBitmap, 0, 0, null);
    canvas.save(Canvas.ALL_SAVE_FLAG);
    canvas.restore();
    if (!bitmap.isRecycled()) {
        LogUtils.verbose("recycle bitmap: " + bitmap.toString());
        bitmap.recycle();
    }
    // Restore the view
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}
 
源代码17 项目: MyBookshelf   文件: ConvertUtils.java
/**
 * 把view转化为bitmap(截图)
 * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html
 */
public static Bitmap toBitmap(View view) {
    int width = view.getWidth();
    int height = view.getHeight();
    if (view instanceof ListView) {
        height = 0;
        // 获取listView实际高度
        ListView listView = (ListView) view;
        for (int i = 0; i < listView.getChildCount(); i++) {
            height += listView.getChildAt(i).getHeight();
        }
    } else if (view instanceof ScrollView) {
        height = 0;
        // 获取scrollView实际高度
        ScrollView scrollView = (ScrollView) view;
        for (int i = 0; i < scrollView.getChildCount(); i++) {
            height += scrollView.getChildAt(i).getHeight();
        }
    }
    view.setDrawingCacheEnabled(true);
    view.clearFocus();
    view.setPressed(false);
    boolean willNotCache = view.willNotCacheDrawing();
    view.setWillNotCacheDrawing(false);
    // Reset the drawing cache background color to fully transparent for the duration of this operation
    int color = view.getDrawingCacheBackgroundColor();
    view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素)
    if (color != Color.WHITE) {
        view.destroyDrawingCache();
    }
    view.buildDrawingCache();
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap == null) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(cacheBitmap, 0, 0, null);
    canvas.save();
    canvas.restore();
    if (!bitmap.isRecycled()) {
        bitmap.recycle();
    }
    // Restore the view
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}
 
源代码18 项目: AndroidPicker   文件: ConvertUtils.java
/**
 * 把view转化为bitmap(截图)
 * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html
 */
public static Bitmap toBitmap(View view) {
    int width = view.getWidth();
    int height = view.getHeight();
    if (view instanceof ListView) {
        height = 0;
        // 获取listView实际高度
        ListView listView = (ListView) view;
        for (int i = 0; i < listView.getChildCount(); i++) {
            height += listView.getChildAt(i).getHeight();
        }
    } else if (view instanceof ScrollView) {
        height = 0;
        // 获取scrollView实际高度
        ScrollView scrollView = (ScrollView) view;
        for (int i = 0; i < scrollView.getChildCount(); i++) {
            height += scrollView.getChildAt(i).getHeight();
        }
    }
    view.setDrawingCacheEnabled(true);
    view.clearFocus();
    view.setPressed(false);
    boolean willNotCache = view.willNotCacheDrawing();
    view.setWillNotCacheDrawing(false);
    // Reset the drawing cache background color to fully transparent for the duration of this operation
    int color = view.getDrawingCacheBackgroundColor();
    view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素)
    if (color != Color.WHITE) {
        view.destroyDrawingCache();
    }
    view.buildDrawingCache();
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap == null) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(cacheBitmap, 0, 0, null);
    canvas.save();
    canvas.restore();
    if (!bitmap.isRecycled()) {
        LogUtils.verbose("recycle bitmap: " + bitmap.toString());
        bitmap.recycle();
    }
    // Restore the view
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}
 
源代码19 项目: YiBo   文件: HomePageActivity.java
@Override
protected void onNewIntent(Intent newIntent) {
	super.onNewIntent(newIntent);
	if (Logger.isDebug()) {
		Log.v(TAG, "onNewIntent……" + ", Intent : " + newIntent);
	}

	LocalAccount account = (LocalAccount)newIntent.getSerializableExtra("ACCOUNT");
	if (account == null) {
		updateContentView(null);
		return;
	}
	int contentType = newIntent.getIntExtra("CONTENT_TYPE", Skeleton.TYPE_MY_HOME);

	sheJiaoMao.setCurrentAccount(account); // 设置当前帐号
	skeleton.setCurrentAccount(account, true);
	skeleton.setContentType(contentType);

	// move to head
	ListView lvMicroBlog = (ListView) this.findViewById(R.id.lvMicroBlog);
	if (lvMicroBlog != null) {
		ListAdapter adapter = lvMicroBlog.getAdapter();
		CacheAdapter<?> cacheAdapter = AdapterUtil.getCacheAdapter(adapter);
		//有可能处于分组中
		if (contentType == Skeleton.TYPE_MY_HOME
			&& cacheAdapter instanceof GroupStatusesListAdapter) {
			Cache cache = CacheManager.getInstance().getCache(account);
			AdapterCollectionCache adapterCache = (AdapterCollectionCache)cache;
			if (adapterCache != null) {
				cacheAdapter = adapterCache.getMyHomeListAdapter();
				lvMicroBlog.setAdapter(cacheAdapter);
				TextView tvTitle = (TextView)this.findViewById(R.id.tvTitle);
				String title = "";
				if (account.getUser() != null) {
				    title += account.getUser().getScreenName() + "@";
				}
				title += account.getServiceProvider().getSpName();
				tvTitle.setText(title);
			}
		}
        if (cacheAdapter != null && cacheAdapter.refresh()) {
            cacheAdapter.reclaim(ReclaimLevel.MODERATE);
        }
        if (lvMicroBlog.getChildCount() > 1) {
        	lvMicroBlog.setSelection(1);
        }
	}
}
 
源代码20 项目: Dashchan   文件: ViewUnit.java
public void notifyUnbindListView(ListView listView) {
	for (int i = 0; i < listView.getChildCount(); i++) {
		notifyUnbindView(listView.getChildAt(i));
	}
}