2013-07-07 3 views
-4

나는 클립에있는 총알 수를 계산하는 게임에 TextView이 있습니다. 촬영 버튼을 누르면 총알 수에서 1을 뺍니다. 어떻게 할 수 있습니까?버튼 클릭시 TextView의 카운트 다운

TextView rounds; 

public void onClick(View arg0) { 
    // TODO Auto-generated method stub 
    switch(arg0.getId()) { 
    case R.id.button1: 
     //What to do ? 
     break; 
+0

왜 아래로 투표를? 이것은 금지를 원치 않는 제 3 번째 계정입니다! – user2558256

+0

http://stackoverflow.com/questions/4768969/how-do-i-change-textview-value-inside-java-code & http://stackoverflow.com/questions/12613898/android-textview-value –

+0

너 downvotes 금지하지 마십시오. – Simon

답변

1

정말 기본적인 안드로이드 튜토리얼을 읽어야합니다. 그것은 우리와 많은 시간을 절약 할 수 있습니다.

case R.id.button1: { 
    int tmp = Integer.valueOf(rounds.getText().toString(); 
    rounds.setText(String.valueOf(tmp-1)); 
} 
break; 
+0

조언 주셔서 감사합니다! 효과가있다. – user2558256

0
public class game extends Activity{ //<- Change this (game)! 

private int shoot=10; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.game); //<- Change this! 
    } 

private void update(Button button){ 
    rounds.setText("Bullets"+ shoot--); //Update the information of the button 
} 

public void onClick(View button) { //When you click 
    update((Button) button); //Activates the update 

} 

또는 당신은 또한 사용할 수 있습니다

TextView rounds; 

public void onClick(View arg0) { 

switch(arg0.getId()) { 
case R.id.button1: 
    rounds.setText("Bullets"+ shoot--); 
    break; 
} 
관련 문제