开发者

repetition in the menu

开发者 https://www.devze.com 2023-03-01 14:57 出处:网络
Please help me out regarding repeating the menu. First class: public class A extends Activity { /** Called when the activity is first created. */

Please help me out regarding repeating the menu.

First class:

public class A extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.settings:     
                Intent intent = new Intent(this, ShowSettings.class);
                  startActivity(intent);
            break;
            case R.id.services:     
                Intent intent2 = new Intent(this, Test.class);
                startActivity(intent2);
              break;
            case R.id.Quit: 

                finish();



                break;
            default:    
            break;
        }
        return true;
    }
}

second class

public class Test extends ListActivity  {


            @Override
            public void onCreate(Bundle savedInstanceState) {
               over here i will be fetching the list from the server 
            }

            @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                MenuInflater inflater = getMenuInflater();
                inflater.inflate(R.menu.menu, menu);
                return true;
            }

            @Override
            public boolean onOptionsItemSelected(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.settings:     
                        Intent intent = new Intent(this, ShowSettings.class);
                          startActivity(intent);
                    break;
                    case R.id.services:     
                        Intent intent2 = new Intent(this, Test.class);
                        startActivity(intent2);
                      break;
                    case R.id.Quit: 

                        finish();



                        break;
                    default:    
                    break;
                }
                return true;
            }
        }

I have tried in this way but it was not working.

previous logcat

04-30 23:32:09.906: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test2' (No such file or directory)
04-30 23:32:09.906: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test2' (No such file or directory)
04-30 23:32:09.906: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test' (No such file or directory)
04-30 23:32:09.906: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test' (No such file or directory)
04-30 23:32:26.345: ERROR/MemoryHeapBase(65): error opening /dev/pmem: No such file or directory
04-30 23:32:26.345: ERROR/SurfaceFlinger(65): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
04-30 23:32:26.475: ERROR/libEGL(65): couldn't load <libhgl.so> library (Cannot load library: load_library[984]: Library 'libhgl.so' not found)
04-30 23:32:27.234: ERROR/libEGL(76): couldn't load <libhgl.so> library (Cannot load library: load_library[984]: Library 'libhgl.so' not found)
04-30 23:32:31.694: ERROR/BatteryService(65): Could not open '/sys/class/power_supply/usb/online'
04-30 23:32:31.694: ERROR/BatteryService(65): Could not open '/sys/class/power_supply/battery/batt_vol'
04-30 23:32:31.694: ERROR/BatteryService(65): Could not open '/sys/class/power_supply/battery/batt_temp'
04-30 23:32:32.445: ERROR/EventHub(65): could not get driver version for /dev/input/mouse0, Not a typewriter
04-30 23:32:32.445: ERROR/EventHub(65): could not get driver version for /dev/input/mice, Not a typewriter
04-30 23:32:33.116: ERROR/System(65): Failure starting core service
04-30 23:32:33.116: ERROR/System(65): java.lang.SecurityException
04-30 23:32:33.116: ERROR/System(65):     at android.os.BinderProxy.transact(Native Method)
04-30 23:32:33.116: ERROR/System(65):     at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
04-30 23:32:33.116: ERROR/System(65):     at android.os.ServiceManager.addService(ServiceManager.java:72)
04-30 23:32:33.116: ERROR/System(65):     at com.android.server.ServerThread.run(SystemServer.java:162)
04-30 23:32:33.125: ERROR/AndroidRuntime(65): Crash logging skipped, no checkin service
04-30 23:32:35.514: ERROR/LockPatternKeyguardView(65): Failed to bind to GLS while checking for account
04-30 23:32:43.175: ERROR/ActivityThread(109): Failed to find provider info for com.google.settings
04-30 23:32:43.205: ERROR/ActivityThread(109): Failed to find provider info for com.google.settings
04-30 23:32:49.344: ERROR/ApplicationContext(65): Couldn't create directory for SharedPreferences file shared_prefs/wallpaper-hints.xml
04-30 23:32:50.144: ERROR/vold(26): Cannot start volume '/sdcard' (volume is not bound)
04-30 23:32:52.407: ERROR/ActivityThread(106): Failed to find provider info for android.server.checkin
04-30 23:32:55.918: ERROR/MediaPlayerService(30): Couldn't open fd for content://settings/system/notification_sound
04-30 23:32:55.949: ERROR/MediaPlayer(65): Unable to to create media player
04-30 23:32:56.969: ERROR/ActivityThread(106): Failed to find provider info for android.server.checkin
04-30 23:32:57.237: ERROR/ActivityThread(106): Failed to find provider info for android.server.checkin
04-30 23:33:18.468: ERROR/AndroidRuntime(212): Uncaught handler: thread main exiting due to uncaught exception
04-30 23:33:18.848: ERROR/AndroidRuntime(212): java.lang.NullPointerException
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at android.widget.SimpleAdapter.getCount(SimpleAdapter.java:95)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at android.widget.AdapterView.checkFocus(AdapterView.java:689)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at android.widget.AdapterView$AdapterDataSetObserver.onInvalidated(AdapterView.java:813)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at android.database.DataSetObservable.notifyInvalidated(DataSetObservable.java:43)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at android.widget.BaseAdapter.notifyDataSetInvalidated(BaseAdapter.java:54)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at android.widget.SimpleAdapter$SimpleFilter.publishResults(SimpleAdapter.java:391)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:282)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at android.os.Looper.loop(Looper.java:123)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at android.app.ActivityThread.main(ActivityThread.java:4203)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at java.lang.reflect.Method.invokeNative(Native Method)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at java.lang.reflect.Method.invoke(Method.java:521)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
04-30 23:33:18.848: ERROR/AndroidRuntime(212):     at dalvik.system.NativeStart.main(Native Method)
04-30 23:33:29.837: ERROR/ActivityThread(109): Failed to find provider info for android.server.checkin
04-30 23:33:29.849: ERROR/GoogleHttpClient(109): Error recording stats
04-30 23:33:29.849: ERROR/GoogleHttpClient(109): java.lang.IllegalArgumentException: Unknown URL content://android.server.checkin/stats
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at android.content.ContentResolver.insert(ContentResolver.java:476)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.google.android.net.GoogleHttpClient.executeWithoutRewriting(GoogleHttpClient.java:241)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.google.android.net.GoogleHttpClient.execute(GoogleHttpClient.java:278)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.google.android.net.GoogleHttpClient.execute(GoogleHttpClient.java:348)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.google.android.providers.enhancedgooglesearch.SuggestionProvider.sendGenieSearchRequest(SuggestionProvider.java:587)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.google.android.providers.enhancedgooglesearch.SuggestionProvider.querySearchSuggestions(SuggestionProvider.java:316)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.google.android.providers.enhancedgooglesearch.SuggestionProvider.query(SuggestionProvider.java:262)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at android.content.ContentProvider$Transport.query(ContentProvider.java:129)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at android.content.ContentResolver.query(ContentResolver.java:152)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.SearchableSuggestionSource.getSuggestions(SearchableSuggestionSource.java:268)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.SearchableSuggestionSource.getCursor(SearchableSuggestionSource.java:216)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.SearchableSuggestionSource.getSuggestions(SearchableSuggestionSource.java:166)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.AbstractSuggestionSource$1.call(AbstractSuggestionSource.java:75)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.AbstractSuggestionSource$1.call(AbstractSuggestionSource.java:68)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:256)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at java.util.concurrent.FutureTask.run(FutureTask.java:122)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.QueryMultiplexer$SuggestionRequest.run(QueryMultiplexer.java:172)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.PerTagExecutor$Limiter$1.run(PerTagExecutor.java:106)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at java.lang.Thread.run(Thread.java:1060)
04-30 23:33:29.849: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.SuggestionProvider$SuggestionThread.run(SuggestionProvider.java:102)
04-30 23:33:29.998: ERROR/ActivityThread(109): Failed to find provider info for android.server.checkin
04-30 23:33:30.047: ERROR/GoogleHttpClient(109): Error recording stats
04-30 23:33:30.047: ERROR/GoogleHttpClient(109): java.lang.IllegalArgumentException: Unknown URL content://android.server.checkin/stats
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at android.content.ContentResolver.insert(ContentResolver.java:476)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.google.android.net.GoogleHttpClient.executeWithoutRewriting(GoogleHttpClient.java:241)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.google.android.net.GoogleHttpClient.execute(GoogleHttpClient.java:278)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at开发者_开发百科 com.google.android.net.GoogleHttpClient.execute(GoogleHttpClient.java:348)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.google.android.providers.enhancedgooglesearch.SuggestionProvider.sendGenieSearchRequest(SuggestionProvider.java:587)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.google.android.providers.enhancedgooglesearch.SuggestionProvider.querySearchSuggestions(SuggestionProvider.java:316)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.google.android.providers.enhancedgooglesearch.SuggestionProvider.query(SuggestionProvider.java:262)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at android.content.ContentProvider$Transport.query(ContentProvider.java:129)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at android.content.ContentResolver.query(ContentResolver.java:152)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.SearchableSuggestionSource.getSuggestions(SearchableSuggestionSource.java:268)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.SearchableSuggestionSource.getCursor(SearchableSuggestionSource.java:216)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.SearchableSuggestionSource.getSuggestions(SearchableSuggestionSource.java:166)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.AbstractSuggestionSource$1.call(AbstractSuggestionSource.java:75)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.AbstractSuggestionSource$1.call(AbstractSuggestionSource.java:68)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:256)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at java.util.concurrent.FutureTask.run(FutureTask.java:122)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.QueryMultiplexer$SuggestionRequest.run(QueryMultiplexer.java:172)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.PerTagExecutor$Limiter$1.run(PerTagExecutor.java:106)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at java.lang.Thread.run(Thread.java:1060)
04-30 23:33:30.047: ERROR/GoogleHttpClient(109):     at com.android.globalsearch.SuggestionProvider$SuggestionThread.run(SuggestionProvider.java:102)

instead of emulator when i tried to run on the android i got the following logcat

repetition in the menu


I have tried only the onCreateOptionsMenu method of the code provided in the link you have mentioned and it works.

From the code (still from the link, in the MenuHandler.java)

  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.settings:     
            Intent intent = new Intent(this, ShowSettings.class);
              startActivity(intent);
        break;
        case R.id.services:     
            Intent intent2 = new Intent(this, Test.class);
            startActivity(intent2);
          break;
        case R.id.Quit: 

Make sure you call the new activity as

Intent intent = new Intent(activity, ShowSettings.class);
activity.startActivity(intent);

Same inside the case R.id.services

0

精彩评论

暂无评论...
验证码 换一张
取 消