Guest User

Untitled

a guest
Nov 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. class ViewUtil {
  2. fun disableButtonsTemporarily(viewList:ArrayList<View>){
  3. try{
  4. //DISABLE THE VIEW
  5. updateViewsClickableAttribute(viewList, false)
  6.  
  7. //ENABLE THE VIEWS
  8. val handler = Handler()
  9. handler.postDelayed( {
  10. // Do something after 5s = 5000ms
  11. updateViewsClickableAttribute(viewList, true)
  12. }, 500)
  13. }catch (e: Exception){
  14. e.printStackTrace()
  15. }
  16. }
  17.  
  18. fun updateViewsClickableAttribute(viewList:ArrayList<View>, clickable:Boolean){
  19. var size = 0;
  20. if (viewList!=null)
  21. size = viewList.size
  22.  
  23. if (size==0){
  24. return
  25. }
  26. for (i in 0..size-1) {
  27. val view = viewList.get(i)
  28. if (view!=null){
  29.  
  30. var canUpdateAttribute = true
  31. if (canUpdateAttribute)
  32. view.isClickable = clickable
  33. }
  34. }
  35. }
  36.  
  37. fun removeView(view: View) {
  38. val parent = getParent(view)
  39. if (parent != null) {
  40. parent!!.removeView(view)
  41. }
  42. }
  43.  
  44. fun replaceView(currentView: View, newView: View) {
  45. val parent = getParent(currentView) ?: return
  46. val index = parent!!.indexOfChild(currentView)
  47. removeView(currentView)
  48. removeView(newView)
  49. parent!!.addView(newView, index)
  50. }
  51.  
  52. private fun getParent(view: View): ViewGroup {
  53. return view.parent as ViewGroup
  54. }
  55. }
Add Comment
Please, Sign In to add comment