2011-02-13 70 views
0

我需要知道是否可以在另一個類中增加一個字符串。該類在onclick方法中調用,每次單擊按鈕時,我都希望文本顯示下一個字符串。這是可能的,如果是這樣的話,我將不勝感激任何指導。在Textview中每次調用類時都會增加字符串

謝謝。

回答

0

當然你可以!只需在你的班級中創建一個getter和setter方法。

public class Foo() { 
... 
private String fooString; 

    public void setFooString() { 
    fooString = fooString + "my new string"; 
    } 

    public String getFooString() { 
    return fooString; 
    } 
} 
+0

感謝您的答覆,我非常感激。我是否需要在兩個類中都包含這兩種方法? – Raj 2011-02-13 20:39:48

0
public class A { 
    public static String blub = "my string"; 
} 

public class B { 
    /** 
    * Called when the button is clicked. 
    */ 
    public void myOnClickMethod() { 
     A.blub += " add this, too"; 
    } 
} 
相關問題