Change ImageView after few seconds

前端 未结 2 772
你的背包
你的背包 2021-01-26 10:47

I\'m trying to implement a simple activity that will let user to insert a password. I\'ve a gridview with the 9 images to use and 4 imageviews that will be the selected images (

相关标签:
2条回答
  • 2021-01-26 11:38

    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.

    0 讨论(0)
  • 2021-01-26 11:42

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

    0 讨论(0)
提交回复
热议问题