Hide A Layout After 10 Seconds In Android?

前端 未结 6 396
旧巷少年郎
旧巷少年郎 2021-02-04 07:30

I have a layout displayed on a button click.I want to hide that layout after 10 seconds.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(         


        
6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 08:24

        public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        pd=ProgressDialog.show(this,"","Loading, Please wait .. ",true);
    
        setTitle("set title");
        final Handler uiThreadCallback=new Handler();
        final Runnable runInUIThread= new Runnable(){
            public void run(){
                fnDraw();
                pd.dismiss();
    
            }
        }; 
        new Thread(){
            @Override public void run(){
                uiThreadCallback.post(runInUIThread);
            }
        }.start();
    }
    public void fnDraw(){
        setContentView(R.layout.define ur xml if any);
        i1=(ImageView)findViewById(R.id.i1);
        t1=(TextView)findViewById(R.id.t1);
        t2=(TextView)findViewById(R.id.t2);
    
        timerRegister=new Timer();
        lIteration=0;
        checkTime=new TimerTask(){
            public void run(){
                if(lIteration==1){
                    timerRegister.cancel();
                    uiDrawThreadCallback.post(runInUIDrawThread);
                }
                lIteration++;
                return;
            }
        };
        timerRegister.scheduleAtFixedRate(checkTime,0,10000);
    }
    final Handler uiDrawThreadCallback=new Handler();
    final Runnable runInUIDrawThread= new Runnable(){
        @Override
        public void run(){
            fnDrawAgain();
        }
    };
    public void fnDrawAgain(){
        Intent intent=new Intent(this,new class you want to open.class);
        startActivity(intent);
    }
    

    }

    try it m sure it gonna work in ur on create screen

提交回复
热议问题