2012-05-23 4 views
0

간단한 카운터를 만들고 싶습니다. 화면을 클릭하면 textvalue의 값이 증가합니다.화면을 클릭하면 TextView 값이 변경됩니다.

그래서 내 활동.

public class MyTasbih extends Activity implements View.OnClickListener { 

//Button btn; 
TextView t; 
int i=0; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    //btn=(Button)findViewById(R.id.button); 
    t=(TextView)findViewById(R.id.t); 

    //btn.setOnClickListener(this); 
    t.setOnClickListener(this); 

    updateCounter(); 

} 

public void onClick(View view) { 
    i++; 
    updateCounter(); 

} 

private void updateCounter() { 

    t.setText(i); 
} 
} 

크래시. 나는 초보자입니다. 제발 도와주세요.

+0

확인합니다. 어디에서 충돌했는지 알 수 있습니다. – Ran

답변

0

나는 이것을 확인하는 편리한 일식 없지만되지 업데이트해야합니다 :

private void updateCounter() { 
    t.setText(Integer.toString(i)); 
} 
1

이 시도하십시오 및 Eclipse에서보기 로그 캣이라는이

private void updateCounter() { 

    t.setText(String.valueOf(i)); 
} 
+0

네, 맞습니다! 감사! – Gezzeg

0
public class MyTasbih extends Activity implements View.OnClickListener { 

//Button btn; 
TextView t; 
int i=0; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main6); 

    //btn=(Button)findViewById(R.id.button); 
    t=(TextView)findViewById(R.id.t); 

    //btn.setOnClickListener(this); 
    t.setOnClickListener(this); 

    updateCounter(); 

} 

public void onClick(View view) { 
    i++; 
    updateCounter(); 

} 

private void updateCounter() { 

    t.setText(String.valueOf(i)); 
} 
} 
관련 문제