-1

I'm trying to get the values of a listview that has an edittext for the user to place the values, and I get them when saving the information. I got it; The problem is that I use listview.getchildat (i) and I can only get the children that are visible on the screen, but sometimes they are more than 50 children and I can not get more than the 8 visible, I would like to see if there is any way to get Values not visible. This is the code I have and I get only visible children:

for (i = 0; i < feedList.size(); i++) {
            View v = lv.getChildAt(i);
            System.out.println("Posicion i: " + i);
            TextView cobro = null;
            try {

                cobro = (TextView) v.findViewById(R.id.col_cobro);
                System.out.println("CobroValidador: " + cobro.getText().toString());
                sumaValidaCobro += Convert(cobro.getText().toString());
                tstSuma += Convert(cobro.getText().toString());
            } catch (Exception ex) {
                validaCobrado++;
                System.out.println("Valida cobrado: " + validaCobrado);
          //      tstSuma += Convert(cobro.getText().toString());

            }
        }

  I'm using a listview with 4 col, this is the adapter.

 SimpleAdapter simpleAdapter = new SimpleAdapter(this, feedList, R.layout.view_item, new String[]{"doc", "emp", "original", "saldo", "cobro"}, new int[]{R.id.col_doc_id, R.id.col_emp, R.id.col_original, R.id.col_saldo, R.id.col_cobro});
        lv.setAdapter(simpleAdapter);

I need to get the new values of the last col, it's an EditText

FeedList is the initial adapter with which the listview is loaded, but the user can enter the values manually in the listview. When I save I can not use the original, I need to get all the data that the user entered. Any way to achieve this?

Greetings.

joe06
  • 418
  • 4
  • 17

2 Answers2

0

ListView has a recycling mechanism, invisibel items might be recycled and lost the data they hold. See this answer for more details.

If you wish to reserve data from those EditTexts in the ListView, you might want to implement your own adapter, and put a listener on every EditText when inflating items.

Also, For a more modern, flexible, and performant approach to displaying lists, use RecyclerView.

LionHere
  • 9
  • 1
  • 2
  • I added the listview adapter, I'm using 4 col at the adapter – joe06 May 16 '17 at 15:43
  • @Heisenberg06 regardless of col number, you could still try it this way. Just replace `EditText` with your list item type(like `LinearLayout` etc.). – LionHere May 16 '17 at 16:00
  • @Heisenberg06 you might want to check out my _**another idea**_ in my edit – LionHere May 16 '17 at 16:14
  • What do you wanna say with register EditText? – joe06 May 17 '17 at 17:51
  • @Heisenberg06 by `register()` I mean 'save' the handlers of `EditText`...or put it another way, send thoes instances of `EditText` to your activity, and hold them, which allow you to `getText()` from them afterwards. You can consider `register()` as one callback method in your parent activity. (sorry for my poor english :P) – LionHere May 18 '17 at 05:49
0

I resolved this problem changing from ListView to RecycleView, works very nice

joe06
  • 418
  • 4
  • 17