How to switch between screens?

后端 未结 6 1242
梦如初夏
梦如初夏 2020-12-31 20:37

I\'m new in the android develop world. I created simple application and created a simple GUI with one button. If the user presses this button, I want to change the screen

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 21:13

    You can do something like this:

    import android.view.View;
    
    /** Called when the activity is first created. */
    public class YourActivity extends Activity implements View.OnClickListener {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Button button = (Button) findViewById(R.id.your_button_id);
            button.setOnClickListener(this);
        }
    
        public void onClick(View v) {
            Intent intent = new Intent(your_present_activity.this, target_activity.class);
            startActivity(intent);
        }
    }
    

提交回复
热议问题