我是Android的初學者,目前我正在開發簡單的應用程序。我有7張照片,我想在用戶觸摸屏幕時逐個更改。這是我的代碼,我的應用在屏幕上的第二次觸摸時崩潰。如果有人能幫助,我會很感激。如何更改onTouch上的圖片?
public class Game extends Activity {
public TextView result;
public ImageView pirveli, meore, mesame, meotxe, mexute, meeqvse, meshvide;
int counter=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
result = (TextView) findViewById(R.id.result);
result.setText("Number of steps made: " + counter);
pirveli = (ImageView) findViewById(R.drawable.pirveli);
meore = (ImageView) findViewById(R.drawable.meore);
mesame = (ImageView) findViewById(R.drawable.mesame);
meotxe = (ImageView) findViewById(R.drawable.meotxe);
mexute = (ImageView) findViewById(R.drawable.mexute);
meeqvse = (ImageView) findViewById(R.drawable.meeqvse);
meshvide= (ImageView) findViewById(R.drawable.meshvide);
}
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction()==0){
result.setText("Number of steps made: " + counter);
counter++;
pirveli.setImageResource(R.drawable.meore);
}
return false;
}
還有一個問題:當我第一次觸摸屏幕時,int計數器沒有增加。我該如何解決它?
請將StackTrace添加到您的帖子中。 – PKeidel 2012-03-12 17:33:40