How to navigate from one screen to another screen

前端 未结 16 1408
失恋的感觉
失恋的感觉 2020-11-29 04:31

How to navigate from one Activity screen to another Activity screen? In the first screen I\'m having one button if I click the button it has to move to another Activity scre

相关标签:
16条回答
  • 2020-11-29 05:01
    Button navigate;
    navigate = findViewById(R.id.button);
    navigate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getApplicationContext(),"Navigate another Activity",Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(MainActivity.this,MainActivity2.class);
                    startActivity(intent);
                }
            });
    
    0 讨论(0)
  • 2020-11-29 05:04

    The most trivial case (called from activity):

    startActivity(new Intent(this, ActivityToLaunch.class));
    

    More details here: http://developer.android.com/guide/topics/fundamentals.html

    0 讨论(0)
  • 2020-11-29 05:04

    In your method fun onCreate(savedInstanceState: Bundle?) add this.

    your_btn_id.setOnClickListener{
    
                val intent = Intent(this, yourpagename::class.java)
                startActivity(intent)
            }
    

    Until now if it doesn't work then, check if these two files are added or not,

    import android.content.Intent
    import kotlinx.android.synthetic.main.activity_otp.*
    
    0 讨论(0)
  • 2020-11-29 05:05
    startActivity(new Intent(this,newActivity.class));
    
    0 讨论(0)
  • 2020-11-29 05:07
    final Context cont = this;
    Button btnClickABC =(Button)findViewById(R.id.btnClickABC);
    btnClickABC.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {                   
                    startActivity(new Intent(cont, NextActivity.class));
    
                }
            });
    
    0 讨论(0)
  • 2020-11-29 05:08

    You can navigate to the next screen using these code snippets:

    Kotlin

    startActivity(Intent(this, LoginActivity::class.java))
    

    Java

    startActivity(new Intent(this, LoginActivity.class))
    

    Here's a reference: Android Developers - Starting another activity

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