Permalink
Browse files

Adding previous button to ActionBar inside activities

  • Loading branch information...
1 parent 8ce4b5b commit 827b672401bbcc0f1bc1fa25e5a365c24d0b8bb3 @kyriog committed Apr 1, 2012
@@ -2,12 +2,14 @@
import com.supinfo.geekquote.model.Quote;
+import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.format.DateFormat;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
@@ -26,6 +28,8 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quoteactivity);
+ ActionBar actionbar = getActionBar();
+ actionbar.setDisplayHomeAsUpEnabled(true);
Bundle extras = getIntent().getExtras();
quote = (Quote) extras.getSerializable("quote");
@@ -47,6 +51,16 @@ protected void onCreate(Bundle savedInstanceState) {
ok.setOnClickListener(this);
}
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch(item.getItemId()) {
+ case android.R.id.home:
+ setResult(RESULT_CANCELED);
+ finish();
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
quote.setRating((int) rating);
}
@@ -1,19 +1,23 @@
package com.supinfo.geekquote;
+import android.app.ActionBar;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
+import android.view.MenuItem;
-public class QuoteRestPreferencesActivity extends PreferenceActivity implements OnPreferenceChangeListener {
+public class QuoteRestPreferencesActivity extends PreferenceActivity implements OnPreferenceChangeListener {
private EditTextPreference RESTURI;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.restpreferences);
+ ActionBar actionbar = getActionBar();
+ actionbar.setDisplayHomeAsUpEnabled(true);
CheckBoxPreference RESTActivated = (CheckBoxPreference) findPreference("rest_activated");
RESTURI = (EditTextPreference) findPreference("rest_uri");
@@ -41,4 +45,11 @@ public boolean onPreferenceChange(Preference pref, Object newValue) {
return true;
}
+ public boolean onOptionsItemSelected (MenuItem item) {
+ switch(item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ }
+ return true;
+ }
}

0 comments on commit 827b672

Please sign in to comment.