Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragment code is completely ignored #4

Closed
bostone opened this issue Nov 29, 2012 · 11 comments
Closed

Fragment code is completely ignored #4

bostone opened this issue Nov 29, 2012 · 11 comments
Labels

Comments

@bostone
Copy link

bostone commented Nov 29, 2012

I have a very simple setup following your demo project

<preference-headers xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:unified="http://schemas.android.com/apk/res/bostone.android.jobrio" >
    <header
        unified:fragment="bostone.android.jobrio.JobrioPreferenceActivity$AccountsFragment"
        unified:title="@string/pref_header_general"
        unified:preferenceRes="@xml/pref_general" />
</preference-headers>

pref_general.xml

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
    <CheckBoxPreference
        android:defaultValue="false"
        android:key="linkedin_login"
        android:summary="@string/pref_description_linkedin_account"
        android:title="@string/pref_title_linkedin_account" />
</PreferenceScreen>

And the java code

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setHeaderRes(R.xml.pref_headers);
        setSharedPreferencesName(getApplicationContext().getPackageName());
        setSharedPreferencesMode(Context.MODE_PRIVATE);
        super.onCreate(savedInstanceState);
        final ActionBar ab = getSupportActionBar();
        ab.setDisplayHomeAsUpEnabled(true);
    }

    public static class AccountsFragment extends UnifiedPreferenceFragment {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }

        @Override
        public void onAttach(Activity activity) {
            super.onAttach(activity);
        }

    }

Preferences screen comes up just fine and checkbox property acts appropriately. What puzzle me is that unified:fragment="bostone.android.jobrio.JobrioPreferenceActivity$AccountsFragment" is seemingly ignored and in fact I can put any gibberish as fragment value and it will not generate any errors. As far as AccountsFragment goes - its onCreate and onAttach methods are never called.

I must be doing something wrong here?

Thanks,

Bo Stone

@saik0
Copy link
Owner

saik0 commented Nov 29, 2012

You should be getting a NoClassDefFound error. Are you building with Eclipse?

@bostone
Copy link
Author

bostone commented Nov 29, 2012

Yes sir. Like I said it has no effect

@saik0
Copy link
Owner

saik0 commented Nov 29, 2012

Please try closing the projects, then quit eclipse. Launch, re-open and clean the library and your project.

@bostone
Copy link
Author

bostone commented Nov 29, 2012

Same thing

@bostone
Copy link
Author

bostone commented Nov 29, 2012

Is there anything special that needs to go into manifest file? I just have a plain simple Activity definition

@saik0
Copy link
Owner

saik0 commented Nov 29, 2012

Is there anything special that needs to go into manifest file? I just have a plain simple Activity definition

No. I am not able to replicate this. Your snippet should work fine, and a bad value for unified:fragment should produce a NoClassDefFound exception. I suspect there is a bug or configuration problem in the build system.

@saik0
Copy link
Owner

saik0 commented Nov 29, 2012

Here is a quick test project I setup using your samples. It also contains the apk that compiled and runs OK. Sorry I cant be of more help.

Edit: Forgot the link!
http://dropbox.saik0.net/preferencetest.zip

@bostone
Copy link
Author

bostone commented Nov 29, 2012

I run the code and I have absolutely the same effect. Runs fine, change unified:fragment="foo", clean, run, no error. Change back - AccountFragments.onCreate is never accessed. I step through your code and I think the problem is that when isSinglePane returns true then fragments are simply ignored. So when I place some logic into fragment - it will never be picked up

@bostone bostone closed this as completed Nov 29, 2012
@bostone bostone reopened this Nov 29, 2012
@saik0
Copy link
Owner

saik0 commented Nov 29, 2012

Take a look at #3

@saik0
Copy link
Owner

saik0 commented Nov 29, 2012

This is a separate issue. Lets continue the discussion on issue #8.

While we're here though, some history: The initial release of the lib was only a "librarized" port of ADT SettingsActivity template because it was quite a bit of code for a minimally useful PreferenceActivity, and reusing the template was not DRY enough. There's still some weirdness from the template to cast off, pull requests welcome.

Edit: wrong issue number -_-

@saik0 saik0 closed this as completed Nov 29, 2012
@vmihalachi
Copy link

Hi, the bug still persist. How can i fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants