0

Im having a problem during an action in my activity. I have created a runnable, that runs on a thread. The thread checks if a textview has been swiped and moves the textview off screen. Once that textview is offscreen it removes it from the linearlayout. The layout does not update the textviews in it and leaves the space that the previous textview was at.

How it is now:

__________           __________            __________
|[item 1]|  ----->   |[item 1]|   ----->   |[item 1]|
|[item 2]|  User     |[swiped]|   item 2   |        |
|[item 3]|  swipes   |[item 3]|   space    |[item 3]|
|[item 4]|  item 2   |[item 4]|   remains  |[item 4]|
|[item 5]|           |[item 5]|            |[item 5]|
----------           ----------            ----------

How I want it to run:

__________           __________            __________
|[item 1]|  ----->   |[item 1]|   ----->   |[item 1]|
|[item 2]|  user     |[swiped]|   removed  |[item 3]|
|[item 3]|  swiped   |[item 3]|   view &   |[item 4]|
|[item 4]|           |[item 4]|   update   |[item 5]|
|[item 5]|           |[item 5]|   space    |        |
----------           ----------            ----------

I hope this explains what is going on and what I have. If not ill add more.

EDIT: If i lock and unlock my screen, it updates the UI, and the views are fixed. It seems I am looking for a refresh or maybe invalidate()?

JstnPwll
  • 8,585
  • 2
  • 33
  • 56
Mishtiff
  • 51
  • 7

1 Answers1

2

You probably want:

LinearLayout.requestLayout()

public void requestLayout()

Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.

Subclasses which override this method should call the superclass method to handle possible request-during-layout errors correctly.

Cory Charlton
  • 8,868
  • 4
  • 48
  • 68
JstnPwll
  • 8,585
  • 2
  • 33
  • 56
  • I appreciate your time. I stood up to go to lunch and locked my phone. I unlocked it before I left for lunch and noticed it had updated the error, so i post my findings on here before leaving. Thanks again! – Mishtiff Nov 13 '15 at 19:10
  • Justin, I have tried to requestLayout on the holding layout of my TextViews, and it does not update the ui. Locking and unlocking the screen still updates. Is it possible that because im running this call in a different thread, it is not getting ran? – Mishtiff Nov 13 '15 at 19:45
  • I think it should be run on the UI thread, see [here](http://stackoverflow.com/questions/24392835/calling-requestlayout-from-a-separate-thread) – JstnPwll Nov 13 '15 at 20:11
  • If i add this code, will it over-write the existing code that the activity was running before? Ive added it, the activity will no longer display, and crashes after 5 seconds – Mishtiff Nov 13 '15 at 20:20
  • I'm not sure what the impact is on your code. It may be that you actually want `invalidate`, but since you're calling from a non-UI thread, you'd use `postInvalidate()`. (See [here](http://stackoverflow.com/questions/5521596/what-does-postinvalidate-do)) – JstnPwll Nov 13 '15 at 20:23
  • I just cant win. =[ It worked once, then crashed the next time it was called. Maybe I should look for a different method to accomplish this task – Mishtiff Nov 13 '15 at 21:27