How to navigate from one screen to another screen

前端 未结 16 1407
失恋的感觉
失恋的感觉 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:09
    Button x.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) 
        {
            Intent i = new Intent(y.this, Activity.class);
            startActivity(i);                   
        }
    });
    

    Here we've defined a listener for Button x. The OS will call this method and start the Activity referenced in Intent i.

    Here's the official tutorial example: http://developer.android.com/guide/tutorials/notepad/notepad-ex2.html

    0 讨论(0)
  • 2020-11-29 05:11
    Button btn = (Button)findViewById(R.id.button1);
    
    btn.setOnClickListener(new View.OnClickListener() {
    
        @Override
        public void onClick(View v) {      
    
            startActivity(new Intent(TestActivity.this,second.class));
    
        }
    });
    
    0 讨论(0)
  • 2020-11-29 05:11
    public void onClick(View v) 
    {
        Intent myintent = new Intent(currentclass.this, nextactivity.class);
        startActivity(myintent);                               
    }
    
    0 讨论(0)
  • 2020-11-29 05:14

    Try this code:

     Button my_btn;
     my_btn = findViewById(R.id.submit_btn);
     my_btn.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
             setContentView(R.layout.activity_2);
         }
     });
    
    0 讨论(0)
提交回复
热议问题