I am trying to get a button to become visible if there is one or more objects in an array, otherwise it will stay invisible.
I am used:
if (positionOverlay.geoPointsArrayList.size() <= 0){
buttonClear.setVisibility(View.GONE);
System.out.println("Clear button hidden");
}
else if (positionOverlay.geoPointsArrayList.size() >= 1) {
buttonClear.setVisibility(View.VISIBLE);
System.out.println("Clear button visible");
}
The problem I am having is that it runs and on start up the array i am using is empty, so the button stays invisible, however when I add objects to the array it still stays invisible, suggesting that it doesnt run the code again.
I have placed the code above in the onCreate, could anyone tell me where i have gone wrong?
When you alter your array of objects you'll need to run the code you have in onCreate
- what you have now only ever checks on startup and isn't linked to the array being altered at all.
So in pseudocode if you have:
array.add("new item");
this.updateButton(); // This is where you have your button code.
array.remove("some other item");
this.updateButton(); // Check if you've gone below the limit again
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.