Java Code Examples for android.widget.ListView#getChildCount()
The following examples show how to use
android.widget.ListView#getChildCount() .
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: ThreadsPage.java From Dashchan with Apache License 2.0 | 6 votes |
@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); } } }
Example 2
Source File: HomePageHeaderDoubleClickListener.java From YiBo with Apache License 2.0 | 6 votes |
@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); } } }
Example 3
Source File: ListBuddiesLayout.java From ListBuddies with Apache License 2.0 | 6 votes |
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; } } }
Example 4
Source File: ViewShot.java From zone-sdk with MIT License | 6 votes |
/** * 截图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; }
Example 5
Source File: TopRecommendFragment.java From letv with Apache License 2.0 | 6 votes |
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(); } } }
Example 6
Source File: ListViewAutoScrollHelper.java From letv with Apache License 2.0 | 6 votes |
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; }
Example 7
Source File: SettingsFragment.java From NMSAlphabetAndroidApp with MIT License | 6 votes |
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(); } } }
Example 8
Source File: FragmentSocialTimeline.java From aptoide-client with GNU General Public License v2.0 | 5 votes |
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()); } }
Example 9
Source File: ListViewAutoScrollHelper.java From android-recipes-app with Apache License 2.0 | 5 votes |
@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; }
Example 10
Source File: SearchResultsActivity.java From iqra-android with MIT License | 5 votes |
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); } }
Example 11
Source File: SwipeRefreshListFragment.java From android-SwipeRefreshListFragment with Apache License 2.0 | 5 votes |
/** * 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()); } }
Example 12
Source File: DrawerContentView.java From flickr-uploader with GNU General Public License v2.0 | 5 votes |
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)); } } }
Example 13
Source File: SwipeRefreshListFragment.java From soas with Apache License 2.0 | 5 votes |
/** * 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()); } }
Example 14
Source File: ListViewActivity.java From easy-guide-android with Apache License 2.0 | 5 votes |
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); } }
Example 15
Source File: ViewUnit.java From Dashchan with Apache License 2.0 | 4 votes |
public void notifyUnbindListView(ListView listView) { for (int i = 0; i < listView.getChildCount(); i++) { notifyUnbindView(listView.getChildAt(i)); } }
Example 16
Source File: HomePageActivity.java From YiBo with Apache License 2.0 | 4 votes |
@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); } } }
Example 17
Source File: ConvertUtils.java From a with GNU General Public License v3.0 | 4 votes |
/** * 把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; }
Example 18
Source File: ConvertUtils.java From AndroidPicker with MIT License | 4 votes |
/** * 把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; }
Example 19
Source File: ConvertUtils.java From MyBookshelf with GNU General Public License v3.0 | 4 votes |
/** * 把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; }
Example 20
Source File: ConvertUtils.java From FilePicker with MIT License | 4 votes |
/** * 把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; }