Таким образом, каждый раз, когда я запускаю этот код мой Android приложение останавливает unexpectdly, и я не понимаю, почему ...Android-приложение всегда останавливается неожиданно, пытаясь обработать событие?
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.TextView;
public class TheStupidTest extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView text1 = (TextView) findViewById(R.id.TextView01);
text1.setText("well this works at least");
Button yButton = (Button) findViewById(R.id.button_yellow);
yButton.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.equals(MotionEvent.ACTION_UP)) {
text1.setText("You pressed the yellow button");
return true;
}
return false;
}
});
}
}
Просмотреть сообщение от Pentium10 о том, как отладить приложение для Android http://stackoverflow.com/questions/3222608/android-error-the-application-has-stopped-unexpectedly-please-try-again/3223115# 3223115 – ccheneson
вы можете взглянуть на DDMS и logcat, чтобы проверить проблемы. Http://goo.gl/i9by –
Почему 'OnTouchListener' вместо' OnClickListener' для кнопки? – adamp