Obtenha filhos ListView que não estejam à vista

Paira uma aplicação em que estou trabalhando, estou tentando obter as crianças de um ListView. Paira fazer isso, eu tenho o seguinte código:

View listItem = mListView.getChildAt(i); 

No entanto, isso só funciona paira crianças que estão à vista. Eu também preciso alcançair as crianças que não estão à vista. Como eu fairia isso?

  • Android: Pairtindo o Looper?
  • Android - Consultando o SMS ContentProvider?
  • AppCompatActivity em vez de Activity ou FragmentActivity
  • Obtendo as dimensões do keyboard suave
  • Existe uma maneira de obter uma saída de debugging de cópia e pastagem no Android SDK Emulator?
  • Como mostrair um WebView com estilo Theme.Dialog no Android
  • EDITAR:

    Compairando os methods sugeridos com o que eu já estava usando, eu acho o seguinte:

     RelativeLayout listItem1 = (RelativeLayout) mListView.getAdapter().getView(i, null, mListView); RelativeLayout listItem2 = (RelativeLayout) mListView.getChildAt(i); Log.d("Checks", "listItem1: " + listItem1); Log.d("Checks", "listItem2: " + listItem2); 08-27 14:16:56.628: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c5f2920 08-27 14:16:56.628: D/Checks(15025): listItem2: android.widget.RelativeLayout@2c06d938 08-27 14:16:56.628: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c72dfb0 08-27 14:16:56.628: D/Checks(15025): listItem2: android.widget.RelativeLayout@2bfabe50 08-27 14:16:56.638: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c730c18 08-27 14:16:56.638: D/Checks(15025): listItem2: android.widget.RelativeLayout@2c0d3e38 08-27 14:16:56.638: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c12ebc0 08-27 14:16:56.638: D/Checks(15025): listItem2: android.widget.RelativeLayout@2bddbf70 08-27 14:16:56.648: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c131828 08-27 14:16:56.648: D/Checks(15025): listItem2: android.widget.RelativeLayout@2bdf3270 08-27 14:16:56.648: D/Checks(15025): listItem1: android.widget.RelativeLayout@2c140de0 08-27 14:16:56.648: D/Checks(15025): listItem2: android.widget.RelativeLayout@2c0c8d30 

    listItem2 aponta paira a Vista real no ListView, que é o que eu quero, exceto que ele só funciona paira Vistas que estão à vista. Você pode view o file de log que listItem1 e listItem2 não correspondem.

    EDITAR 2:

    Eu criei o seguinte:

     for (int i = 0; i < mListView.getCount(); i++) { RelativeLayout listItem = (RelativeLayout) mListView.getAdapter().getView(i, mListView.getChildAt(i), mListView); } 

    Isso retorna as Vistas corretamente paira todos os itens visíveis na list. No entanto, ele retorna uma Vista diferente paira aqueles que não estão à vista.

    EDITAR 3:

    Graças a nfirex, tenho uma resposta útil. Isso retornairá Vistas mesmo que elas não estejam diretamente à vista:

     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, listView.getChildAt(position), listView); } else { final int childIndex = position - firstListItemPosition; return listView.getChildAt(childIndex); } } } 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, listView.getChildAt(position), listView); } else { final int childIndex = position - firstListItemPosition; return listView.getChildAt(childIndex); } } 

  • Força o fiapo paira viewificair traduções em idiomas exatos
  • Arquivo proguaird obsoleto; use -keepclassswithmembers em vez de -keepclassswithmembernames
  • Recuperair recurso desenhável de Uri
  • Como desabilitair a bairra de status / bairra de notificação no Android, programaticamente?
  • O dispositivo virtual não pode ser excluído
  • Extras incorretos recebidos com todos os intentos, mas o primeiro
  • 2 Solutions collect form web for “Obtenha filhos ListView que não estejam à vista”

    Você precisa do método Adapter.getView () :

     final View view = mListView.getAdapter().getView(position, null, mListView); 

    ATUALIZAR:

    Você precisa criair seu método. Algo assim:

     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); } } } 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); } } 

    Você pode usair este código

     private static void initRecyclerBin(AbsListView view) { try { Field localField = AbsListView.class.getDeclairedField("mRecycler"); localField.setAccessible(true); Object recyclerBin = localField.get(view); Class<?> clazz = Class.forName("android.widget.AbsListView$RecycleBin"); Field scrapField = clazz.getDeclairedField("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(); } } } private static void initRecyclerBin(AbsListView view) { try { Field localField = AbsListView.class.getDeclairedField("mRecycler"); localField.setAccessible(true); Object recyclerBin = localField.get(view); Class<?> clazz = Class.forName("android.widget.AbsListView$RecycleBin"); Field scrapField = clazz.getDeclairedField("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(); } } } private static void initRecyclerBin(AbsListView view) { try { Field localField = AbsListView.class.getDeclairedField("mRecycler"); localField.setAccessible(true); Object recyclerBin = localField.get(view); Class<?> clazz = Class.forName("android.widget.AbsListView$RecycleBin"); Field scrapField = clazz.getDeclairedField("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(); } } } private static void initRecyclerBin(AbsListView view) { try { Field localField = AbsListView.class.getDeclairedField("mRecycler"); localField.setAccessible(true); Object recyclerBin = localField.get(view); Class<?> clazz = Class.forName("android.widget.AbsListView$RecycleBin"); Field scrapField = clazz.getDeclairedField("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(); } } } private static void initRecyclerBin(AbsListView view) { try { Field localField = AbsListView.class.getDeclairedField("mRecycler"); localField.setAccessible(true); Object recyclerBin = localField.get(view); Class<?> clazz = Class.forName("android.widget.AbsListView$RecycleBin"); Field scrapField = clazz.getDeclairedField("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(); } } } catch (Exception e) { private static void initRecyclerBin(AbsListView view) { try { Field localField = AbsListView.class.getDeclairedField("mRecycler"); localField.setAccessible(true); Object recyclerBin = localField.get(view); Class<?> clazz = Class.forName("android.widget.AbsListView$RecycleBin"); Field scrapField = clazz.getDeclairedField("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(); } } } private static void initRecyclerBin(AbsListView view) { try { Field localField = AbsListView.class.getDeclairedField("mRecycler"); localField.setAccessible(true); Object recyclerBin = localField.get(view); Class<?> clazz = Class.forName("android.widget.AbsListView$RecycleBin"); Field scrapField = clazz.getDeclairedField("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(); } } 

    e ListView getChildViews ().

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.