我想调试onClick
中的SaveActivity
方法:
public class SaveActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_save);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
// For the Back Button
// (http://developer.android.com/training/implementing-navigation/ancestral.html)
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This is called when the Home (Up) button is pressed
// in the Action Bar.
Intent parentActivityIntent = new Intent(this, MainActivity.class);
parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(parentActivityIntent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
public void onClick(View view) {
switch (view.getId()) { // <-- On this line is my Breakpoint
case R.id.location_save:
EditText formName = (EditText) findViewById(R.id.location_name);
String locationName = formName.getText().toString();
EditText formDesc = (EditText) findViewById(R.id.location_desc);
String locationDesc = formDesc.getText().toString();
// Example for New York
String locationLatitude = "40.714353";
String locationLongitude = "-74.005973";
DatabaseHandler db = new DatabaseHandler(this);
Location newLocation = new Location(locationName, locationDesc,
locationLatitude, locationLongitude);
db.addLocation(newLocation);
Intent myIntent = new Intent(SaveActivity.this, DetailActivity.class);
myIntent.putExtra("id", newLocation.getId());
SaveActivity.this.startActivity(myIntent);
}
}
}
现在我在onClick方法的switch
- Statemant上添加了一个断点。然后我点击activity_save.xml
中的这个按钮:
<Button
android:id="@+id/location_save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/location_save" >
</Button>
所以它应该停在我的断点处,但没有任何事情发生 我错了什么?
答案 0 :(得分:2)
在按钮布局中添加此项以将方法绑定到其onClick:
android:onClick="onClick"