How do I access PreferenceFragment by id?

后端 未结 2 990
鱼传尺愫
鱼传尺愫 2021-02-10 15:16

I have a Honeycomb style preferences. I define the headers:


  
2条回答
  •  再見小時候
    2021-02-10 15:46

    I have found the solution. There is no way to access fragment directly, but it can be found via ListAdapter. In your PreferenceActivity you can write:

    int fragmentId = R.id.pref_sharing;
    for (int i = 0; i < getListAdapter().getCount(); i++)
    {
        Header header = (Header) getListAdapter().getItem(i);
        if (fragmentId == header.id)
        {
            // You can access a fragment name (class)
            String fragment = header.fragment;
            // You can access fragment arguments
            Bundle args = header.fragmentArguments;
        }
    }
    

    I didn't find a way to disable a header list item but I created a workaround based on this code.

提交回复
热议问题