我想知道当我按下按钮时,如何跳转到下一个活动的代码。

huangapple go评论57阅读模式
英文:

I want to know the code to goto next activity when I press a button

问题

我是 Android Studio 的初学者。我想要知道在我按下按钮时如何跳转到下一个界面的代码。你能给我展示一个例子吗?

英文:

I am a beginner in android studio. I want to know the code to go to the next activity when I press a button. Could you please show me an example?

答案1

得分: 1

button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
      Intent intent = new Intent(this, NewActivity.class);
      startActivity(intent);
   }
});
英文:

Basic code would be:

button = (Button) findViewById(R.id.button);
      button.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            Intent intent = new Intent(this, NewActivity.class);
            startActivity(intent);
         }
      });

huangapple
  • 本文由 发表于 2020年10月19日 16:33:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/64423761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定