22
33import android .app .ActionBar ;
44import android .app .Activity ;
5+ import android .os .AsyncTask ;
56import android .os .Bundle ;
6- import android .util .Log ;
77import android .view .Menu ;
88import android .view .MenuItem ;
99
@@ -16,7 +16,8 @@ protected void onCreate(Bundle savedInstanceState) {
1616 super .onCreate (savedInstanceState );
1717 setContentView (R .layout .activity_main );
1818 ActionBar actionBar = getActionBar ();
19- // actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
19+ actionBar .setDisplayOptions (ActionBar .DISPLAY_SHOW_HOME
20+ | ActionBar .DISPLAY_SHOW_TITLE | ActionBar .DISPLAY_SHOW_CUSTOM );
2021 }
2122
2223 @ Override
@@ -27,25 +28,37 @@ public boolean onCreateOptionsMenu(Menu menu) {
2728
2829 @ Override
2930 public boolean onOptionsItemSelected (MenuItem item ) {
30- menuItem = item ;
31- menuItem .setActionView (R .layout .progressbar );
32- menuItem .expandActionView ();
33- doSomeThingLong ();
31+ switch (item .getItemId ()) {
32+ case R .id .menu_load :
33+ menuItem = item ;
34+ menuItem .setActionView (R .layout .progressbar );
35+ menuItem .expandActionView ();
36+ TestTask task = new TestTask ();
37+ task .execute ("test" );
38+ break ;
39+ default :
40+ break ;
41+ }
3442 return true ;
3543 }
3644
37- private void doSomeThingLong () {
38- Runnable runnable = new Runnable () {
39- public void run () {
40- try {
41- Thread .sleep (200 );
42- } catch (InterruptedException e ) {
43- e .printStackTrace ();
44- }
45- Log .e ("Lars" , "FuCK" );
46- menuItem .collapseActionView ();
45+ private class TestTask extends AsyncTask <String , Void , String > {
46+
47+ @ Override
48+ protected String doInBackground (String ... params ) {
49+ // Simulate something long running
50+ try {
51+ Thread .sleep (2000 );
52+ } catch (InterruptedException e ) {
53+ e .printStackTrace ();
4754 }
48- };
49- new Thread (runnable ).start ();
50- }
55+ return null ;
56+ }
57+
58+ @ Override
59+ protected void onPostExecute (String result ) {
60+ menuItem .collapseActionView ();
61+ menuItem .setActionView (null );
62+ }
63+ };
5164}
0 commit comments