Android – add menu to sub preferences screen

I have a menu that appears in my preferenceactivity. In my children's preferences screen, I lost the menu (no Pop-Up). How do I pop up a menu for children?

thank you.

Example:

<PreferenceScreen
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:persistent="true">
  <PreferenceCategory
    android:title="some category"
    android:persistent="true"
    android:orderingFromXml="true">
    <PreferenceScreen
      android:title="some child screen"
      android:summary="some child summary">
      <PreferenceCategory
         ...

The first preference screen has a menu, but when you click on a submenu, there is no menu. How can you add a menu?

resolvent:

I have encountered a similar problem. The following is what I have done to overcome this problem

In the preferenceactivity oncreate method,

        final PreferenceScreen childPref = (PreferenceScreen) findPreference("childPrefId");
        childPref .setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference)
            {
                Intent intent = new Intent(PreferenceActivity.this, YourSettings.class);
                intent.setAction("ShowChildPref");
                startActivity(intent);                    
                return true;
            }
        });

        Intent intent = getIntent();
        if(intent.getAction() != null && intent.getAction().equals("ShowChildPref"))
        {                
            setPreferenceScreen(childPref);

            /*Set Flags here based on intent what kind of menu to create in OnPrepareMenu.*/
        }
    }

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>