Java Code Examples for android.widget.ListView.getChildAt()

The following are Jave code examples for showing how to use getChildAt() of the android.widget.ListView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: adyen-android   File: PaymentMethodSelectionFragment.java   View Source Code Vote up 8 votes
private void resizeListView(ListView listView, boolean isBottomList) {
    ListAdapter adapter = listView.getAdapter();
    int count = adapter.getCount();
    int itemsHeight = 0;
    // Your views have the same layout, so all of them have
    // the same height
    View oneChild = listView.getChildAt(0);
    if (oneChild == null) {
        return;
    }
    itemsHeight = oneChild.getHeight();
    // Resize your list view
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) listView.getLayoutParams();
    params.height = isBottomList ? itemsHeight * count + itemsHeight / 2 : itemsHeight * count;
    listView.setLayoutParams(params);
}
 
Example 2
Project: lighthouse   File: PodcastsActivity.java   View Source Code Vote up 8 votes
private void updatePodcastRows() {
    ListView list = getListView();
    int first = list.getFirstVisiblePosition();
    int last = list.getLastVisiblePosition();
    for (int i = first; i <= last; i++) {
        View view = list.getChildAt(i - first);
        list.getAdapter().getView(i, view, list);
    }
}
 
Example 3
Project: prevent   File: PreventFragment.java   View Source Code Vote up 7 votes
public void updateTimeIfNeeded(String packageName) {
    if (scrolling || mAdapter == null) {
        return;
    }
    ListView l = getListView();
    int size = mAdapter.getCount();
    for (int i = 0; i < size; ++i) {
        View view = l.getChildAt(i);
        if (view == null || view.getTag() == null || view.getVisibility() != View.VISIBLE) {
            continue;
        }
        ViewHolder holder = (ViewHolder) view.getTag();
        if (PackageUtils.equals(packageName, holder.packageName)) {
            holder.updatePreventView(mActivity);
            holder.running = mActivity.getRunningProcesses().get(packageName);
            holder.summaryView.setText(StatusUtils.formatRunning(mActivity, holder.running));
        } else if (holder.running != null) {
            holder.summaryView.setText(StatusUtils.formatRunning(mActivity, holder.running));
        }
    }
}
 
Example 4
Project: boohee_v5.6   File: ListViewCompatDonut.java   View Source Code Vote up 7 votes
static void scrollListBy(ListView listView, int y) {
    int firstPosition = listView.getFirstVisiblePosition();
    if (firstPosition != -1) {
        View firstView = listView.getChildAt(0);
        if (firstView != null) {
            listView.setSelectionFromTop(firstPosition, firstView.getTop() - y);
        }
    }
}
 
Example 5
Project: GitHub   File: DownloadAdapter.java   View Source Code Vote up 6 votes
/**
 * 局部更新API
 */
public void notifyItemChanged(ListView listview, int position){
    int firstPos = listview.getFirstVisiblePosition();
    int lastPos = listview.getLastVisiblePosition();
    Job job = mData.get(position);
    if(position >= firstPos && position <= lastPos){
        View view = listview.getChildAt(position - firstPos); //NOTE
        DownloadAdapter.VH vh = (DownloadAdapter.VH) view.getTag();
        vh.progress.setProgress(job.progress);
        if(job.progress == 100){
            vh.btn.setText("完成");
        }
    }
}
 
Example 6
Project: GitHub   File: Tool.java   View Source Code Vote up 6 votes
private static void setListItemsStyle(ConfigBean bean) {
    if(bean.type == DefaultConfig.TYPE_MD_SINGLE_CHOOSE || bean.type == DefaultConfig.TYPE_MD_MULTI_CHOOSE){
        ListView listView =  bean.alertDialog.getListView();
       // listView.getAdapter().
        if(listView!=null && listView.getAdapter() !=null){
            int count = listView.getChildCount();
            for(int i=0;i<count;i++){
                View childAt = listView.getChildAt(i);
                if(childAt ==null){
                    continue;
                }
                CheckedTextView itemView = (CheckedTextView) childAt.findViewById(android.R.id.text1);
                Log.e("dd",itemView+"-----"+ i);
                if(itemView !=null) {
                    itemView.setCheckMarkDrawable(R.drawable.bg_toast);
                    //itemView.setCheckMarkTintList();

                   // itemView.setCheckMarkTintList();
                    //itemView.setCheckMarkTintList();

                }

            }

        }

    }
}
 
Example 7
Project: qmui   File: QMUIViewHelper.java   View Source Code Vote up 6 votes
/**
 * 判断 ListView 是否已经滚动到底部
 *
 * @param listView 需要被判断的 ListView
 * @return
 */
public static boolean isListViewAlreadyAtBottom(ListView listView) {
    if (listView.getAdapter() == null || listView.getHeight() == 0) {
        return false;
    }

    if (listView.getLastVisiblePosition() == listView.getAdapter().getCount() - 1) {
        View lastItemView = listView.getChildAt(listView.getChildCount() - 1);
        if (lastItemView != null && lastItemView.getBottom() == listView.getHeight()) {
            return true;
        }
    }
    return false;
}
 
Example 8
Project: Chorus-RF-Laptimer   File: PilotsSetupFragment.java   View Source Code Vote up 6 votes
public void updatePilotNames() {
    ListView mListView = (ListView)mRootView.findViewById(R.id.lvPilots);
    int count = AppState.getInstance().deviceStates.size();
    for (int i = 0; i < count; i++) {
        View convertView = mListView.getChildAt(i);
        if (convertView != null) {
            EditText pilotName = (EditText) convertView.findViewById(R.id.editPilotName);
            String curPilotName = AppState.getInstance().deviceStates.get(i).pilotName;
            pilotName.setText(curPilotName);
        }
    }
}
 
Example 9
Project: TPondof   File: Utils.java   View Source Code Vote up 6 votes
/**
 * @see <a href="http://stackoverflow.com/questions/24811536/android-listview-get-item-view-by-position" >android - listview get item view by position
</a>
 * @param pos
 * @param listView
 * @return
 */
public static 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 10
Project: Bartout   File: DrinkBeverageActivity.java   View Source Code Vote up 6 votes
private 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
Project: BBSSDK-for-Android   File: BBSPullToRequestView.java   View Source Code Vote up 6 votes
public void onScroll(Scrollable scrollable, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
	if(scrollable != null && scrollable instanceof ListView) {
		final ListView listview = (ListView) scrollable;
		View c = listview.getChildAt(0);
		if (c != null) {
			scrollHeight = getScroll();
			OnScrolledToY(scrollHeight);
			if (BBSPullToRequestView.this.onScrollListener != null) {
				BBSPullToRequestView.this.onScrollListener.OnScrolledTo(scrollHeight);
			}
		}
	}
}
 
Example 12
Project: chromium-for-android-56-debug-video   File: AppMenu.java   View Source Code Vote up 6 votes
/**
 * Notifies the menu that the contents of the menu item specified by {@code menuRowId} have
 * changed.  This should be called if icons, titles, etc. are changing for a particular menu
 * item while the menu is open.
 * @param menuRowId The id of the menu item to change.  This must be a row id and not a child
 *                  id.
 */
public void menuItemContentChanged(int menuRowId) {
    // Make sure we have all the valid state objects we need.
    if (mAdapter == null || mMenu == null || mPopup == null || mPopup.getListView() == null) {
        return;
    }

    // Calculate the item index.
    int index = -1;
    int menuSize = mMenu.size();
    for (int i = 0; i < menuSize; i++) {
        if (mMenu.getItem(i).getItemId() == menuRowId) {
            index = i;
            break;
        }
    }
    if (index == -1) return;

    // Check if the item is visible.
    ListView list = mPopup.getListView();
    int startIndex = list.getFirstVisiblePosition();
    int endIndex = list.getLastVisiblePosition();
    if (index < startIndex || index > endIndex) return;

    // Grab the correct View.
    View view = list.getChildAt(index - startIndex);
    if (view == null) return;

    // Cause the Adapter to re-populate the View.
    list.getAdapter().getView(index, view, list);
}
 
Example 13
Project: chromium-for-android-56-debug-video   File: LocationBarLayout.java   View Source Code Vote up 6 votes
/**
 * Invalidates all of the suggestion views in the list.  Only applicable when this
 * is visible.
 */
public void invalidateSuggestionViews() {
    if (!isShown()) return;
    ListView suggestionsList = mSuggestionList;
    for (int i = 0; i < suggestionsList.getChildCount(); i++) {
        if (suggestionsList.getChildAt(i) instanceof SuggestionView) {
            suggestionsList.getChildAt(i).postInvalidateOnAnimation();
        }
    }
}
 
Example 14
Project: fragmentnav   File: Androids.java   View Source Code Vote up 6 votes
public static View locateListViewItem(ListView listView, ItemViewLocate locate, Object compareObj) {
    for (int i = 0; i < listView.getChildCount(); i++) {
        View child = listView.getChildAt(i);
        if (locate.locate(child, compareObj)) {
            return child;
        }
    }

    return null;
}
 
Example 15
Project: decoy   File: ListViewUtil.java   View Source Code Vote up 6 votes
public static Object getViewHolderByIndex(ListView listView, int index) {
	int firstVisibleFeedPosition = listView.getFirstVisiblePosition() - listView.getHeaderViewsCount();
	int lastVisibleFeedPosition = listView.getLastVisiblePosition() - listView.getHeaderViewsCount();

	//只有获取可见区域的
	if (index >= firstVisibleFeedPosition && index <= lastVisibleFeedPosition) {
		View view = listView.getChildAt(index - firstVisibleFeedPosition);
		Object tag = view.getTag();
		return tag;
	} else {
		return null;
	}
}
 
Example 16
Project: CXJPadProject   File: ChatUtils.java   View Source Code Vote up 6 votes
/**
 * 单个更新某个条目   只有可见的时候更新progress,
 * @param progress 当前进度
 * @param position 位置
 * @param lv_message Listview
    */
public static void updateProgressPartly(int progress,int position,ListView lv_message){
	int firstVisiblePosition = lv_message.getFirstVisiblePosition();
	int lastVisiblePosition = lv_message.getLastVisiblePosition();
	if(position>=firstVisiblePosition && position<=lastVisiblePosition){
		View view = lv_message.getChildAt(position - firstVisiblePosition);
		if(view.getTag() instanceof ImageMessageHolder){
			ImageMessageHolder vh = (ImageMessageHolder)view.getTag();
			vh.sobot_pic_progress_round.setProgress(progress);
		}
	}
}
 
Example 17
Project: QMUI_Android   File: QMUIViewHelper.java   View Source Code Vote up 6 votes
/**
 * 判断 ListView 是否已经滚动到底部。
 *
 * @param listView 需要被判断的 ListView。
 * @return ListView 已经滚动到底部则返回 true,否则返回 false。
 */
public static boolean isListViewAlreadyAtBottom(ListView listView) {
    if (listView.getAdapter() == null || listView.getHeight() == 0) {
        return false;
    }

    if (listView.getLastVisiblePosition() == listView.getAdapter().getCount() - 1) {
        View lastItemView = listView.getChildAt(listView.getChildCount() - 1);
        if (lastItemView != null && lastItemView.getBottom() == listView.getHeight()) {
            return true;
        }
    }
    return false;
}
 
Example 18
Project: GitHub   File: RefreshContentWrapper.java   View Source Code Vote up 5 votes
@Override
    public AnimatorUpdateListener onLoadingFinish(final RefreshKernel kernel, final int footerHeight, int startDelay, final int duration) {
        if (mScrollableView != null && kernel.getRefreshLayout().isEnableScrollContentWhenLoaded()) {
            if (!canScrollDown(mScrollableView)) {
                return null;
            }
            if (mScrollableView instanceof AbsListView && !(mScrollableView instanceof ListView) && Build.VERSION.SDK_INT < 19) {
                if (startDelay > 0) {
                    kernel.getRefreshLayout().getLayout().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            ((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration);
                        }
                    }, startDelay);
                } else {
                    ((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration);
                }
                return null;
            }
            return new AnimatorUpdateListener() {
                int lastValue = kernel.getSpinner();
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    int value = (int) animation.getAnimatedValue();
                    try {
                        if (mScrollableView instanceof ListView) {
                            if (Build.VERSION.SDK_INT >= 19) {
                                ((ListView) RefreshContentWrapper.this.mScrollableView).scrollListBy(value - lastValue);
                            } else {
//                                ListViewCompat.scrollListBy((ListView) mScrollableView, value - lastValue);
                                ListView listView = (ListView) RefreshContentWrapper.this.mScrollableView;
                                final int firstPosition = listView.getFirstVisiblePosition();
                                if (firstPosition == ListView.INVALID_POSITION) {
                                    return;
                                }
                                final View firstView = listView.getChildAt(0);
                                if (firstView == null) {
                                    return;
                                }
                                final int newTop = firstView.getTop() - (value - lastValue);
                                listView.setSelectionFromTop(firstPosition, newTop);
                            }
                        } else {
                            mScrollableView.scrollBy(0, value - lastValue);
                        }
                    } catch (Throwable ignored) {
                        //根据用户反馈,此处可能会有BUG
                    }
                    lastValue = value;
                }
            };
        }
        return null;
    }
 
Example 19
Project: Rxjava2.0Demo   File: RefreshContentWrapper.java   View Source Code Vote up 5 votes
@Override
    public AnimatorUpdateListener onLoadingFinish(final RefreshKernel kernel, final int footerHeight, int startDelay, final int duration) {
        if (mScrollableView != null && kernel.getRefreshLayout().isEnableScrollContentWhenLoaded()) {
            if (!canScrollDown(mScrollableView)) {
                return null;
            }
            if (mScrollableView instanceof AbsListView && !(mScrollableView instanceof ListView) && Build.VERSION.SDK_INT < 19) {
                if (startDelay > 0) {
                    kernel.getRefreshLayout().getLayout().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            ((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration);
                        }
                    }, startDelay);
                } else {
                    ((AbsListView) mScrollableView).smoothScrollBy(footerHeight, duration);
                }
                return null;
            }
            return new AnimatorUpdateListener() {
                int lastValue = kernel.getSpinner();
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    int value = (int) animation.getAnimatedValue();
                    try {
                        if (mScrollableView instanceof ListView) {
                            if (Build.VERSION.SDK_INT >= 19) {
                                ((ListView) RefreshContentWrapper.this.mScrollableView).scrollListBy(value - lastValue);
                            } else {
//                                ListViewCompat.scrollListBy((ListView) mScrollableView, value - lastValue);
                                ListView listView = (ListView) RefreshContentWrapper.this.mScrollableView;
                                final int firstPosition = listView.getFirstVisiblePosition();
                                if (firstPosition == ListView.INVALID_POSITION) {
                                    return;
                                }
                                final View firstView = listView.getChildAt(0);
                                if (firstView == null) {
                                    return;
                                }
                                final int newTop = firstView.getTop() - (value - lastValue);
                                listView.setSelectionFromTop(firstPosition, newTop);
                            }
                        } else {
                            mScrollableView.scrollBy(0, value - lastValue);
                        }
                    } catch (Throwable ignored) {
                        //根据用户反馈,此处可能会有BUG
                    }
                    lastValue = value;
                }
            };
        }
        return null;
    }
 
Example 20
Project: orgzly-android   File: ListViewUtils.java   View Source Code Vote up 5 votes
public static View getViewIfVisible(ListView listView, int pos) {
    return listView.getChildAt(pos - listView.getFirstVisiblePosition());
}