Skip to content

Commit 38c088d

Browse files
committed
Wrong order of params in creating menu items, Home button now jumps out of current sample
1 parent 64baf6b commit 38c088d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

sample/src/main/java/com/loopj/android/http/sample/SampleParentActivity.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
package com.loopj.android.http.sample;
2020

21+
import android.annotation.TargetApi;
2122
import android.app.Activity;
2223
import android.content.Context;
2324
import android.graphics.Color;
25+
import android.os.Build;
2426
import android.os.Bundle;
2527
import android.util.Log;
2628
import android.view.Menu;
@@ -90,6 +92,8 @@ protected void onCreate(Bundle savedInstanceState) {
9092
setContentView(R.layout.parent_layout);
9193
setTitle(getSampleTitle());
9294

95+
setHomeAsUpEnabled();
96+
9397
urlEditText = (EditText) findViewById(R.id.edit_url);
9498
headersEditText = (EditText) findViewById(R.id.edit_headers);
9599
bodyEditText = (EditText) findViewById(R.id.edit_body);
@@ -127,8 +131,8 @@ public boolean onPrepareOptionsMenu(Menu menu) {
127131

128132
@Override
129133
public boolean onCreateOptionsMenu(Menu menu) {
130-
menu.add(Menu.NONE, MENU_USE_HTTPS, R.string.menu_use_https, Menu.NONE).setCheckable(true);
131-
menu.add(Menu.NONE, MENU_CLEAR_VIEW, R.string.menu_clear_view, Menu.NONE);
134+
menu.add(Menu.NONE, MENU_USE_HTTPS, Menu.NONE, R.string.menu_use_https).setCheckable(true);
135+
menu.add(Menu.NONE, MENU_CLEAR_VIEW, Menu.NONE, R.string.menu_clear_view);
132136
return super.onCreateOptionsMenu(menu);
133137
}
134138

@@ -142,6 +146,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
142146
case MENU_CLEAR_VIEW:
143147
clearOutputs();
144148
return true;
149+
case android.R.id.home:
150+
finish();
151+
return true;
145152
}
146153
return super.onOptionsItemSelected(item);
147154
}
@@ -345,4 +352,12 @@ public AsyncHttpClient getAsyncHttpClient() {
345352
public void setAsyncHttpClient(AsyncHttpClient client) {
346353
this.asyncHttpClient = client;
347354
}
355+
356+
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
357+
private void setHomeAsUpEnabled() {
358+
if (Integer.valueOf(Build.VERSION.SDK) >= 11) {
359+
if (getActionBar() != null)
360+
getActionBar().setDisplayHomeAsUpEnabled(true);
361+
}
362+
}
348363
}

0 commit comments

Comments
 (0)