VOID:在同一个按钮上调用静态和非静态

VOID: static and non-static called on same button

我有按钮,onclick="weboscio"。

我想在点击时做两件事:

public void web(View view) {
    Intent intent = new Intent(this, about.class);
    startActivity(intent); 
    //opens a new layout

还有:

 public static void warning(Context context, int id, int titleResId, int textResId, PendingIntent intent) {

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(titleResId);   
    ....etc....
    // to open a pop-up window

只需将两个空隙合二为一 activity 并在单击按钮时调用它。我搜索了很多,但没有有用的..我也试过:

public static void weboscio(String args[]) {
        home something = new something();
        something.web();
        new something().warning();

它显然只适用于非静态空隙..而且我在 .web(HERE) 和 .warning(HERE) 中遇到错误。

weboscio = onclick function

home = main java activity

web = activity supposed to open new layout

warning = activity supposed to display some warning on new layout

好了,再看一遍问题,明白是怎么回事了。您只是错误地调用了静态方法。

改为这样做:

public static void weboscio(String args[]) {
    home something = new something();
    something.web();
    home.warning(...);

静态方法是通过 class 调用的,而不是 class 的实例。

这是一个例子:

String x = new String("Hello");
x.concat("World"); // non-static

String y = String.join("Hello", "World"); // static