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
You need method Adapter.getView():
final View view = mListView.getAdapter().getView(position, null, mListView);
UPDATE:
You need to create your method. Something like this:
public View getViewByPosition(int position, ListView listView) {
final int firstListItemPosition = listView.getFirstVisiblePosition();
final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;
if (position < firstListItemPosition || position > lastListItemPosition ) {
return listView.getAdapter().getView(position, null, listView);
} else {
final int childIndex = position - firstListItemPosition;
return listView.getChildAt(childIndex);
}
}
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<View>[] scrapViews;
scrapViews = (ArrayList<View>[]) 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().