Change ImageView after few seconds

回眸只為那壹抹淺笑 提交于 2019-12-02 09:28:45

Approach 1)

Let the thread sleep in doInBackground, but change the resource in

@Override
protected void onPostExecute(Void aVoid) {}

method of the AsyncTask. This method has access to the UI thread.

Approach 2)

Another way might be to use

YourActivity.this.runOnUiThread(new Runnable() {
  public void run() {
    YourActivity.this.passField1.setImageResource(R.drawable.e00)
  }
});

(called from doInBackground) where passfield is not a local variable but class variable.

But approach 1 is the preferred way, I suggest you try that way first.

I think you would better use View.postDelayed(Runnable, long) in the onClickListener of your ImageViews to do this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!