2014-09-28 174 views

回答

3

其實,您沒有設置監聽器。所以你應該在setContentView(R.layout.activity_my);之後加changeText()

+0

你的意見是第一。也非常感謝你。 – Sokaz 2014-09-28 09:46:46

+0

我剛剛做到了。我會把你們兩個都提高,但我沒有代表這麼做.. – Sokaz 2014-09-28 13:10:17

+0

謝謝!:) @ Sokaz – PageNotFound 2014-09-28 13:14:26

3

調用此方法changeText()裏面onCreate()方法您的活動

您的活動應該是這樣的:

public class MyActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_my); 
     changeText(); 
    } 

    public void changeText(){ 

     final Button button = (Button) findViewById(R.id.button1); 
     final TextView text = (TextView)findViewById(R.id.largetext); 

     button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 

       button.setText("Button has been pressed"); 
       text.setText("The large text has been changed"); 
      } 
     }); 

    } 
} 
+0

謝謝!這工作! – Sokaz 2014-09-28 09:26:50