简体   繁体   中英

Android validate items inside RecycleView

I'm having a big form inside a recycleview, with multiple repeating items. Think of it like multiple forms: data of car 1, data of car 2 etc. under each other.

Now I'd like to validate all data before saving. Basically the problem is, that the views might not be visible when the user presses the save button.

What's a working way to do this?

My idea would be to scroll manually to each form viewholder THEN validate those, and just stop at the first invalid cell.

But is there a better way? Because this is a bit hacky to me. Is there a way to force a recycleview to actually create a view without it being visible on screen?

Thanks

You should do your validation things on your dataList, for example you have a big array in your activity and you passed it to your adapter.after user clicks on save button you should start validating process on your list(not your adapter). for example in your Activity you have an ArrayList of car object (carList) and you passed it to your adapter.after clicking on save button you should do something like this in your activity class:

for(int i=0;i<carList.size();i++)
{
   if(!isDataValid(carList.get(i)))
     //do your stuff here
}
//notify your adapter here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM