Search code examples
androidimagebuttonvisible

hide one image and visible another image when i clicked the button in android


this is my code;

ib=(ImageButton)findViewById(R.id.imagebutton1);
ib1.setImageResource(i);
Toast.makeText(MainActivity.this,"Fail",1000).show();
Thread.sleep(10000);
ib1.setImageResource(R.drawable.bck_image1);

please give some suggestion as soon as possible.


Solution

  • Try below snippet might be helpful

    ib1.setImageResource(i);
    Toast.makeText(MainActivity.this,"Fail",1000).show();
    android.os.Handler mHandler = new android.os.Handler();
    android.os.Handler mHandler = new android.os.Handler();
        mHandler.postDelayed(new Runnable()
        {
    
            public void run()
            {
                ib1.setImageResource(R.drawable.bck_image1);
        }},1000);