DELETE FROM
package com.example.android.pets; import android.content.Intent; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompactActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; public class CatalogActivity extends AppCompactActivity { @Override protected void onCreate(Budle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_catalog); // Setup FAB to open EditorActivity FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View view){ Intent intent = new Intent(CatalogActivity.this, EditorActivity.class); startActivity(intent); } }); } @Override public boolean onCreateOptionsMenu(Menu menu){ // Inflate the menu options from the res/menu/menu_catalog.xml file. // This adds menu items to the app bar. getMenuInflater().inflate(R.menu.menu_catalog, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item){ // User clicked on a menu option in the app bar overflow menu switch (item.getItemId()){ case R.id.action_insert_dummy_data: return true; case R.id.action_delete_all_entries: return true; } return super.onOptionsItemSelected(item); } }
package com.example.android.pets; import android.os.Bundle; import android.support.v4.app.NavUtils; import android.support.v7.app.AppCompactActivity; import android.text.TextUtils; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.Spinner; public class EditorActivity extends AppCompactActivity { private EditText mNameEditText; private EditText mBreedEditText; private EditText mWeightEditText; private Spinner mGenderSpinner; private int mGender = 0; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_editor); mNameEditText = (EditText) findViewById(R.id.edit_pet_name); mBreedEditText = (EditText) findViewById(R.id.edit_pet_breed); mWeightEditText = (EditText) findViewById(R.id.edit_pet_weight); mGenderSpinner = (Spinner) findById(R.id.spinner_gender); setupSpinner(); } } private void setupSpinner(){ ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_gender_options, android.R.layout.simple_spinner_item); genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); mGenderSpinner.setAdapter(genderSpinnerAdapter); mGenderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){ @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id){ String selection = (String) parent.getItemAtPosition(position); if (!TextUtils.isEmpty(selection)){ if (selection.equals(getString(R.string.gender_male))){ mGender = 1; } else if (selection.equals(getSTring(R.string.gender_female))){ mGender = 2; } else { mGender = 0; } } } @Override public void onNothingSelected(AdapterView<?> parent){ mGender = 0; } }); } @Override public boolean onCreateOptionsMenu(Menu menu){ getMenuInflater().inflate(R.menu.menu_editor, menu); return true; } @Override public boolean onOptionItemSelected(MenuItem item){ switch (item.getItemId()){ case R.id.action_save: return true; case R.id.action_delete: return true; case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); }