Listview Getchildat Giving Nullpointer For Not Visible Elements (android)
When I select one of the items from the listview that is not visible when the activity is created it throws an exception becuase those that are not visible are null. As you see, I
Solution 1:
I've solved the problem.
In order to show also the items of the list view that were not visible, those that caused the NullPointers, I've replaced the line of code which crashed the app. Here it is:
Replace:
LinearLayoutll= (LinearLayout) lerroa.getChildAt(i);
For this one:
LinearLayoutll= (LinearLayout) lerroa.getChildAt(i -lerroa.getFirstVisiblePosition()).findViewById(R.id.LinearLayout3);
getVisiblePosition allows us playing with the first item shown at the LinearLayout and so avoids any NullPointer.
I know this is a bit shoddy and that is not the best way to code what I want to achieve. In spite of this, I've seen so many times the same error on the internet but without any correct answare. I wish this would be usefull for others.
Have a nice code!
Post a Comment for "Listview Getchildat Giving Nullpointer For Not Visible Elements (android)"