在Android Studio海豚中调用公共void例程

bkhjykvo  于 2022-12-21  发布在  Android
关注(0)|答案(1)|浏览(145)
> package com.example.mytest;
> import androidx.appcompat.app.AppCompatActivity;
> 
> import android.icu.text.SimpleDateFormat;
> import android.os.Bundle;
> import android.widget.TextView;
> 
> import java.util.Arrays;
> import java.util.Date;
> import java.util.Locale;
> 
> public class MainActivity extends AppCompatActivity {
>    @Override
> protected void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.activity_main);
>     }
> 
> PrintScreen();
>  
> public void PrintScreen() {
> System.out.println("This is a test");    
>     }
> }

如何在MainActivity(Android Studio海豚)中调用公共void方法PrintScreen()?它不接受上述代码。谢谢

0qx6xfy6

0qx6xfy61#

这是您应该做的。在onCreate中调用PrintScreen();

public class MainActivity extends AppCompatActivity {
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
    PrintScreen();
 }
 
  
 public void PrintScreen() {
 System.out.println("This is a test");    
     }
 }

相关问题