0

我想在我的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);

    }
}

}

现在我switch在 onClick 方法中的 -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>

所以它应该在我的断点处停止,但什么也没发生。
我做错了什么?

4

1 回答 1

2

在你的按钮布局中添加这个以将方法绑定到它的 onClick:

android:onClick="onClick"
于 2013-05-13T07:48:30.223 回答