Android “Only the original thread that created a view hierarchy can touch its views.”

后端 未结 28 3200
鱼传尺愫
鱼传尺愫 2020-11-21 04:44

I\'ve built a simple music player in Android. The view for each song contains a SeekBar, implemented like this:

public class Song extends Activity implement         


        
28条回答
  •  天涯浪人
    2020-11-21 05:18

    In my case, the caller calls too many times in short time will get this error, I simply put elapsed time checking to do nothing if too short, e.g. ignore if function get called less than 0.5 second:

        private long mLastClickTime = 0;
    
        public boolean foo() {
            if ( (SystemClock.elapsedRealtime() - mLastClickTime) < 500) {
                return false;
            }
            mLastClickTime = SystemClock.elapsedRealtime();
    
            //... do ui update
        }
    

提交回复
热议问题