Get ListView children that are not in view

后端 未结 2 673
孤城傲影
孤城傲影 2020-12-05 18:54

For an App I am working on, I\'m trying to get the children of a ListView. To do this I have the following piece of code:

View listItem = mListView.getChildA         


        
2条回答
  •  旧巷少年郎
    2020-12-05 19:49

    You can use this code

    private static void initRecyclerBin(AbsListView view) {
            try {
                Field localField = AbsListView.class.getDeclaredField("mRecycler");
                localField.setAccessible(true);
                Object recyclerBin = localField.get(view);
                Class clazz = Class.forName("android.widget.AbsListView$RecycleBin");
                Field scrapField = clazz.getDeclaredField("mScrapViews");
                scrapField.setAccessible(true);
                ArrayList[] scrapViews;
                scrapViews = (ArrayList[]) scrapField.get(recyclerBin);
                if (null != scrapViews) {
                    int length = scrapViews.length;
                    for (int i = 0, count = 0; i < length; i++) {
                        if (null != scrapViews[i] && !scrapViews[i].isEmpty()) {
                            for (int j = 0; j < scrapViews[i].size(); j++) {
                                scrapViews[i].get(j);//this is the scrapViews
                            }
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    

    and ListView getChildViews().

提交回复
热议问题