GVKun编程网logo

从列表更新OptionMenu(列表的更新)

4

如果您想了解从列表更新OptionMenu的相关知识,那么本文是一篇不可错过的文章,我们将对列表的更新进行全面详尽的解释,并且为您提供关于41889-ApplicationDevelopmentint

如果您想了解从列表更新OptionMenu的相关知识,那么本文是一篇不可错过的文章,我们将对列表的更新进行全面详尽的解释,并且为您提供关于41889 - Application Development in the iOS Environment、Android onCreateOptionsMenu onPrepareOptionsMenu、android – 从片段调用setHasOptionsMenu(true)导致在Activity中多次调用onCreateOptionsMenu、android – 在XE16中调用openOptionsMenu()会导致WindowManager.BadTokenException的有价值的信息。

本文目录一览:

从列表更新OptionMenu(列表的更新)

从列表更新OptionMenu(列表的更新)

我的GUI中有一个由菜单填充的OptionMenu。每次用户运行某个进程时,列表都会更新以反映这一点。有没有一种方法可以基于列表更新OptionMenu?我已经试过self.plotWindow.update()按照这个问题,但无济于事。但是,关闭并重新打开该窗口并不会像您期望的那样刷新OptionMenu。相关代码:

if self.figNum.get() == ''New Figure...'':    if self.figList[-1] == ''New Figure...'':        self.figList.append(1)    else:        self.figList.append(self.figList[-1]+1)    self.plotWindow.update() #tk.Tk() window    self.i = self.figList[-1]else:    self.i = self.figNum.get()

答案1

小编典典

OptionMenu中的选项未绑定到创建它们的列表。因此,更改列表不会更改OptionMenu,您必须自己对其进行更新。

您可以通过获取OptionMenu的来实现menu,并向其中添加命令。以下示例显示了如何执行此操作(基于此答案)。

它显示,即使self.options使用“向列表添加选项”按钮在列表中附加了选项,OptionMenu也不会自动更改。要更新OptionMenu,您可以为此使用“更新选项菜单”按钮self.update_option_menu。此功能从OptionMenu删除所有选项,并为中的每个项目插入一个新选项self.options

import Tkinter as tkclass App():    def __init__(self, parent):        self.parent = parent        self.options = [''one'', ''two'', ''three'']        self.om_variable = tk.StringVar(self.parent)        self.om_variable.set(self.options[0])        self.om_variable.trace(''w'', self.option_select)        self.om = tk.OptionMenu(self.parent, self.om_variable, *self.options)        self.om.grid(column=0, row=0)        self.label = tk.Label(self.parent, text=''Enter new option'')        self.entry = tk.Entry(self.parent)        self.button = tk.Button(self.parent, text=''Add option to list'', command=self.add_option)        self.label.grid(column=1, row=0)        self.entry.grid(column=1, row=1)        self.button.grid(column=1, row=2)        self.update_button = tk.Button(self.parent, text=''Update option menu'', command=self.update_option_menu)        self.update_button.grid(column=0, row=2)    def update_option_menu(self):        menu = self.om["menu"]        menu.delete(0, "end")        for string in self.options:            menu.add_command(label=string,                              command=lambda value=string: self.om_variable.set(value))    def add_option(self):         self.options.append(self.entry.get())         self.entry.delete(0, ''end'')         print self.options    def option_select(self, *args):        print self.om_variable.get()root = tk.Tk()App(root)root.mainloop()

41889 - Application Development in the iOS Environment

41889 - Application Development in the iOS Environment


Faculty of Engineering and information Technology
School of Software
41889 - Application Development in the iOS Environment
42889 - iOS Application Development
Autumn 2018
Assessment Task 2
Individual programming project: BubblePop Game
Due 10 May 2019 at 11:59 pm
This project is worth 30% of the overall mark for this subject.
GitHub Classroom invitation: https://classroom.github.com/a/923tJiqr
Introduction
A client has just hired you to develop a casual iOS game based on an idea he had recently. He
has no programming experiences and only kNows the overall functions the game must have.
You must help him to work out a detailed Graphical User Interface (GUI),design a wellstructured
program and implement the program in the Swift programming language. The final
product shall be thoroughly tested and ready to be submitted to the App Store.
figure 1. Gameplay Mockup figure 2. scoreboard Mockup
Objectives
The purpose of this project is to demonstrate competence in the following skills:
The full software development cycle
iOS App UI and program design
iOS UI programming
Effective use of platform APIs
Program testing
Functionality Specification
The game is called BubblePop (you can call your app a different name if you wish to). In this
game,a number of bubbles are randomly displayed on an iOS device screen. A player pops a
bubble by touching the bubble,and every time they pop a bubble they earn a certain number of
points. Bubbles come in five colours: red,pink,green,blue and black. Each colour corresponds
to a specific number of points and has a specific probability of appearance (see table 1). All
bubbles appear on the screen briefly (see core functionality 9). A player needs to pop as many
bubbles as possible within a certain timeframe (default to 60 seconds) to get high scores. Note

41889留学生作业代做、iOS Environment作业代做、c/c++,Python语言作业代写
that,if a player pops two or more bubbles of the same colour consecutively,they earn 1.5 times
the points for the additional bubbles they pop. Finally,game scores are saved and a high score
board is displayed after a game run is finished. figure 1 provides a rough mock up of what the
main interface may look like. NOTE: figure 1 gives you a guide for your GUI,you may design a
Colour Game Points Probability of Appearance
Red 1 40%
Pink 2 30%
Green 5 15%
Blue 8 10%
Black 10 5%
more sophisticated and more polished GUI for your own work. You will get 1 functionality mark
for each functionality item specified below.
Table 1. Specifications for coloured bubbles
Core Functionalities
1. A player must be able to enter their name before the start of a game run. (You may load
the player‘s name from the GameKit API if you wish. This extra work is not required.)
2. A game timer shall be displayed and it must count down continuously in one-second
intervals. When the timer reaches zero,the game stops.
3. A score shall be displayed. It shall be zero initially and shall be updated every time the
player successfully “pops” a bubble.
4. The default timeframe for a game is 60 seconds,i.e. the game timer starts from 60
seconds and counts down to 0. This number shall be adjustable in the app settings.
5. The maximum number of bubbles displayed on the screen is defaulted to 15,i.e. there
shall be between 0 and 15 bubbles shown on the screen at the same time. This number
shall be adjustable in the app settings.
6. The app randomly decides how many bubbles (up to the maximum allowed bubble
number) shall be displayed on the screen at a time. The bubble colour is decided according
to the Probability of Appearance in Table 1.
7. Bubbles shall be displayed at random positions on the screen with the following
restrictions:
1. The entire bubble shall be displayed within the screen. There shall not be any bubble
with some parts off the screen once it has fully appeared.
2. No two (or more) bubbles shall overlap each other.
8. When a player touches a bubble,the bubble shall be removed from the screen and the
corresponding game points shall be added to the overall score. For example,if the green
bubble in figure 1 was touched,it shall disappear and the score shall increase by 5 game
points. If two or more bubbles of the same colour are popped in a consecutive sequence,
the bubbles after the first one will get 1.5 times their original game points. For example,if
two black bubbles were popped one after the other,25 (10 + 1.5 * 10) shall be added to
the total score. Round to the nearest integer if necessary.
9. The app shall refresh bubbles displayed every game second. That is,after every game
second,the app shall randomly remove a number of bubbles (do not include the bubbles
that have been popped by the player) and replace them with another set of randomly
positioned bubbles. There may be more or less bubbles on the screen compared with the
prevIoUs game second subjected to the restrictions in 5 and 6. In this case,"random"
means chosen by the program,not the user. So you have a lot of discretion in
placement of new bubbles and selection of old bubbles.
10. When the game stops,the player’s score shall be saved in a persistent file (or database)
that contains all players’ names and their highest scores.
11. At the end of the game,a high score board shall be displayed with the names and scores
of the highest ranking players. (See figure 2)
Extended Functionalities (please do not start on these until finishing CFs)
1. In addition to core function 7 and 9,displayed bubbles shall move and go off the screen if
they are not removed earlier. Their moving speed shall increase as the game timer counts
down. You decide the rate of change with respect to the game timer.
2. Animations of game state transitions. For example,one of:
1. Flashing count down 3,2,1 start at the beginning of play
2. Bubbles shrinking,growing,or flying away when removed or tapped
3. score changes or combo lengths displayed with animations in response to taps
3. The highest score in the scoreboard shall be displayed during gameplay.
4. Any cool and useful features that you can think of.
PROGRAM/TEST HINT
Make sure your program works under different iOS devices/simulators (e.g. iPhone4s,iPad
etc.) with different screen sizes and orientations.
For core functionality 4 and 5,the game time and the maximum number of bubbles can be
set in the app settings. How can you make sure their settings are valid? How can you
prevent a user from setting a negative or a very large number for these settings. Think
about how to communicate these constraints to the user in a comfortable way.
Assessment
You will demonstrate your app in your assigned lab on the week of 14 May. Your peers will mark
your app‘s functionality and give you Feedback on usability.
Max score: 30 marks
Functionality: 20 marks (marked by peers)
The Xcode project must unzip successfully and compile without errors.
15 marks for specified functionalities.
Full marks in functionality requires the completion of all CFs and EFs
2 marks for compiling without warnings.
1 mark for operating without unhandled runtime errors.
2 marks for correct display on different screen sizes and orientations.
Code Style: 3 marks (marked by staff)
Deduct up to 1 mark for bad or inconsistent indentation,whitespace,or braces.
Deduct up to 1 mark for bad or misleading comments.
Deduct up to 1 mark for unclear symbol naming.
Program Design: 7 marks (marked by staff)
Data modeling: Do the data structures reflect the problem domain?
Immutable data and idempotent methods: Is the type system used to prevent incorrect
code from being written?
Functional separation: Is the problem broken down into meaningful parts?
Loose coupling: Can parts be changed in isolation of each other?
Extensibility: How easy would it be to add,remove,or change functionality? Could a new
mechanic or new content be added by changing data instead of changing code?
Error handling: Are errors detected at appropriate places? Is the user prevented from
entering invalid input and guided toward valid input?
Late submission
Late submissions may be demonstrated in lab the following week.
Deduct 1 mark per 24 hours late (rounded up). Submissions will not be accepted after the Final
Due Date (7 days after the standard due date).
Please note: Regardless of how many times you have submitted your project,if your final
submission is after the due date it will be considered late and marks will deducted accordingly.
An extension will only be granted if there is a fully documented reason which merits it. The
documentation must be presented to the Subject Coordinator before the due date. Extensions
after the Final Due Date will never be granted under any circumstance. If an extension is
granted that means submission will be accepted up to the extension date without penalty. If an
extension is granted,UTS Online will show the extended due date.
Students may apply for special consideration if they consider that illness or misadventure has
adversely affected their performance.
Bug reports
It is quite possible that errors or ambiguities may be found in the specification. If so,updates
will be placed on UTSOnline and announcements made regarding the amendment. It is your
responsibility to keep up to date on such amendments and ensure you are using the latest
version of the Project Description.
If you discover an error or bug in the provided material,you will receive favorable marking. The
following rules apply:
1. It must be a report on the currently posted version of the material.
2. It must be reported on the UTS Online discussion board to be accepted.
3. It must be a genuine bug. By genuine I mean it requires me to amend the material.
4. If a number of students post a report on the same bug,the first who posted will receive
the mark.
Return of Assessed Project
It is expected that marks will be made available one week after the final due date via
UTSOnline. You will also be given a copy of the marking sheet showing a breakdown of the
marks and Feedback.
Acceptable Practice vs Academic Malpractice
Students should be aware that there is no group work within this subject. All work must be
individual. However,it is considered acceptable practice to adapt code examples found in
the lecture notes,labs and the text book for the assignment. Code adapted from any other
source,particularly the Internet and other student assignments,will be considered
academic malpractice. The point of the assignment is to demonstrate your understanding
of the subject material covered. It‘s not about being able to find solutions on the Internet.
You should also note that assignment submissions will be checked using software that
detects similarities between students programs.
Participants are reminded of the principles laid down in the "Statement of Good Practice
and Ethics in Informal Assessment" in the Faculty Handbook. Assignments in this subject
should be your own original work. Any collaboration with another participant should be
limited to those matters described in the "Acceptable BehavIoUr" section. Any
infringement by a participant will be considered a breach of discipline and will be dealt
with in accordance with the Rules and By-Laws the University. The Faculty penalty for
proven misconduct of this nature is zero marks for the subject. For more information,see
UTS Policy on Academic integrity,plagiarism and cheating
Queries
If you have a question,please contact the instructor as soon as possible.
It is easier to answer queries about specific code. Please upload your code to the GitHub
Classroom repository so that I can read it instead of guessing what it might be.
If the answer to your questions can be found directly in any of the following:
subject outline
task specification
UTS Online discussion board
You will be directed to these locations rather than given a direct answer.

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:[email protected] 

微信:codinghelp

Android onCreateOptionsMenu onPrepareOptionsMenu

Android onCreateOptionsMenu onPrepareOptionsMenu

异步刷新menu :getActivity().supportInvalidateOptionsMenu();


onPrepareOptionsMenu

每次访问都重新填充菜单项


onCreateOptionsMenu 



1. onPrepareOptionsMenu()调用时机。

一般情况下,每次按menu键Framewrok都会先调用onPrepareOptionsMenu(),准备需要显示的菜单。但是当按menu键之前调用了Activity.invalidateOptionsMenu()之后,情况变的不一样,调用完Activity.invalidateOptionsMenu()之后,Framework会立即调用onPrepareOptionsMenu()准备好菜单项数据,之后当用户按menu键时,Framework不会再次调用onPrepareOptionsMenu(),而是将之前准备好的菜单显示出来。这点一定要注意。

2. 清除之前的menu数据。

每次调用onPrepareOptionsMenu()的时候需要首先调用menu.clear()清除一下之前的menu数据,如果不清除的话,之前的menu数据不会被释放,造成内存泄漏。





1、复写onPrepareOptionsMenu方法

 

@Override
 public void onPrepareOptionsMenu(Menu menu) {
  

  menu.clear();//先清除已经建好的menu


  MenuInflater inflater = getActivity().getMenuInflater();

//根据各种条件,重新设置menu

  if (isDeleteIconOnActionBar){
   inflater.inflate(R.menu.delete_action, menu);   
  }else if(isRefreshIconOnActionBar){ 
   inflater.inflate(R.menu.delete_refresh_action, menu);
  }else{
   inflater.inflate(R.menu.main_activity_actions, menu);
  }
  super.onPrepareOptionsMenu(menu);
 }

 

2、在需要修改menu的地方调用

getActivity().supportInvalidateOptionsMenu();




android – 从片段调用setHasOptionsMenu(true)导致在Activity中多次调用onCreateOptionsMenu

android – 从片段调用setHasOptionsMenu(true)导致在Activity中多次调用onCreateOptionsMenu

我有一个简单的Activity包含一个ViewPager.我试图从我的一个片段添加菜单项,但是我有一些奇怪的行为.调用:setHasOptionsMenu(true);从我的片段导致包含Activity的onCreateOptionsMenu()方法在每次更改ViewPager中的片段时被调用.这是正常吗?

解决方法

这是绝对“正常”.它可能不适合您的特定用例,但它绝对是预期的行为.

看看android.support.v4.app.Fragment.setHasOptionsMenu()的源代码:

public void setHasOptionsMenu(boolean hasMenu) {
    if (mHasMenu != hasMenu) {
        mHasMenu = hasMenu;
        if (isAdded() && !isHidden()) {
            mActivity.supportInvalidateOptionsMenu();
        }
    }
}

您可以看到它在其活动上调用了supportInvalidateOptionsMenu(),这最终导致onCreateOptionsMenu()被调用在活动和所有的片段上.当从活动的片段管理器添加/删除片段时,框架将如何管理更新选项菜单.

android – 在XE16中调用openOptionsMenu()会导致WindowManager.BadTokenException

android – 在XE16中调用openOptionsMenu()会导致WindowManager.BadTokenException

我有一个GDE应用程序在XE12中运行良好但现在在转换到GDK之后在XE16中崩溃:19.特别是,在Activity中调用openoptionsMenu()(在这种情况下,打开Live Card上的选项菜单)会导致BadTokenExceptions.

Logcat输出:

04-16 03:36:43.197: E/AndroidRuntime(2465): FATAL EXCEPTION: main
04-16 03:36:43.197: E/AndroidRuntime(2465): Process: com.voidstar.glass.sample.pinDrop,PID: 2465
04-16 03:36:43.197: E/AndroidRuntime(2465): java.lang.RuntimeException: Unable to resume activity {com.voidstar.glass.sample.pinDrop/com.voidstar.glass.sample.pinDrop.MenuActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2828)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2857)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2290)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.app.ActivityThread.access$800(ActivityThread.java:138)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1236)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.os.Looper.loop(Looper.java:149)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.app.ActivityThread.main(ActivityThread.java:5061)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at java.lang.reflect.Method.invokeNative(Native Method)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at java.lang.reflect.Method.invoke(Method.java:515)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at dalvik.system.NativeStart.main(Native Method)
04-16 03:36:43.197: E/AndroidRuntime(2465): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.view.ViewRootImpl.setView(ViewRootImpl.java:561)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at com.android.internal.policy.impl.PhoneWindow.openPanel(PhoneWindow.java:693)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at com.android.internal.policy.impl.PhoneWindow.openPanel(PhoneWindow.java:555)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.app.Activity.openoptionsMenu(Activity.java:2878)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at com.voidstar.glass.sample.pinDrop.MenuActivity.onResume(MenuActivity.java:71)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1194)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.app.Activity.performResume(Activity.java:5316)
04-16 03:36:43.197: E/AndroidRuntime(2465):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2818)
04-16 03:36:43.197: E/AndroidRuntime(2465):     ... 12 more

服务中将活动绑定到Live Card的方法:

@Override
    public int onStartCommand(Intent intent,int flags,int startId) {      
        // This method is called whenever the Glassware is invoked via voice commands or the OK Glass menu.
        if (mLiveCard == null) {    
            Log.d(TAG,"Connecting mLocationManager");

            Criteria criteria = new Criteria();
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);

            PinDropLocationListener listener = new PinDropLocationListener();
            locationListeners.add(listener);
            mLocationManager.requestSingleUpdate(criteria,listener,null);

            mLiveCard = new LiveCard(getBaseContext(),LIVE_CARD_TAG);
            mLiveCard.setViews(new RemoteViews(getPackageName(),R.layout.activity_waiting));
            mLiveCard.attach(this); // Prevent this Service from being killed to free up memory

            Intent menuIntent = new Intent(this,MenuActivity.class); // Since menus can only be attached to Activities,we create an activity to own and launch the menu.
            menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            mLiveCard.setAction(PendingIntent.getActivity(this,menuIntent,0)); // This Intent will be fired whenever the LiveCard is tapped.

            Log.d(TAG,"Publishing LiveCard");
            mLiveCard.publish(PublishMode.REVEAL); // Add the LiveCard to the Timeline and switch to it
            Log.d(TAG,"Done publishing LiveCard");
        } else {
            mLiveCard.navigate(); // Switch to the app if it's already running
        }

        return START_STICKY; // No idea what this does. Your guess is as good as mine.
    }

而有问题的活动:

/**
 * Activity showing the options menu.
 */
public class MenuActivity extends Activity {
    // This is technically an Immersion!
    // Because Services have no UI,we need to open this Activity,which in turn opens its menu!

    PinDropService.MenuBinder mBinder;

    private static String TAG = "PinDropMenu";

    boolean hasLocation;

    /*
     * Links this Activity to the Service that spawned it,so the Menu can send and receive information
     */
    private ServiceConnection mConnection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName name,IBinder service) {
            if (service instanceof PinDropService.MenuBinder) {
                mBinder = (PinDropService.MenuBinder)service;
                hasLocation = mBinder.hasLocation();
                Log.d(TAG,hasLocation ? "Received has location" : "Received no location");
                //openoptionsMenu();
            }
        }

        @Override
        public void onServicedisconnected(ComponentName name) {}
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bindService(new Intent(this,PinDropService.class),mConnection,0);
    }

    @Override
    public void onResume() {
        super.onResume();
        openoptionsMenu();
    }

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

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        if (!hasLocation) {
            menu.findItem(R.id.directions).setVisible(false);
            menu.findItem(R.id.remember).setVisible(false);
        }
        else {
            menu.findItem(R.id.directions).setVisible(true);
            menu.findItem(R.id.remember).setVisible(true);
        }
        return true;
    }

    @Override
    public boolean onoptionsItemSelected(MenuItem item) {
        // Handle item selection.
        switch (item.getItemId()) {
            case R.id.directions:
                mBinder.startNavigation();
                return true;
            case R.id.remember:
                mBinder.addToTimeline(); // Todo: Add Mirror functionality!
                return true;
            case R.id.stop: // IT IS CRITICALLY IMPORTANT TO ADD THIS OR THE GLASSWARE CAN'T BE KILLED IN USERSPACE!
                stopService(new Intent(this,PinDropService.class));
                return true;
            default:
                return super.onoptionsItemSelected(item);
        }
    }

    @Override
    public void onoptionsMenuClosed(Menu menu) {
        // nothing else to do,closing the Activity.
        finish();
    }

    @Override
    public void onStop() {
        super.onStop();
        unbindService(mConnection); // Don't leak Services!
    }
}

点击Live Card会导致立即崩溃,并且上面的Logcat输出被转储.奇怪的是,如果注释掉的openoptionsMenu()被取消注释并且现有的openoptionsMenu()被注释掉,则第一次点击将实际打开菜单.打开菜单的第二次尝试将失败,具有类似的Logcat输出(BadTokenException是主要异常,而不是RuntimeException上的内部异常).

解决方法

As petey said,但除了onResume()之外,还需要覆盖onAttachedToWindow().我的代码现在看起来像:
private boolean isAttached = false;

@Override
public void onAttachedToWindow() {
  super.onAttachedToWindow();
  this.isAttached = true;
  openoptionsMenu();
}

@Override
public void onResume() {
  super.onResume();
  if (this.isAttached)
    openoptionsMenu();
}

今天关于从列表更新OptionMenu列表的更新的分享就到这里,希望大家有所收获,若想了解更多关于41889 - Application Development in the iOS Environment、Android onCreateOptionsMenu onPrepareOptionsMenu、android – 从片段调用setHasOptionsMenu(true)导致在Activity中多次调用onCreateOptionsMenu、android – 在XE16中调用openOptionsMenu()会导致WindowManager.BadTokenException等相关知识,可以在本站进行查询。

本文标签: