L
L
LockUs2017-05-24 14:31:37
Android
LockUs, 2017-05-24 14:31:37

How to make PreferenceFragment (About) like Yandex.Metro?

The question is, how can I add a picture to the PreferenceFragment as it is done in Yandex.Metro (Settings->About)? Maybe there is not PreferenceFragment, but a separate Activity - then how to switch to this activity from PreferenceFragment?
I found options:
1. Add an intent to the Preference with an indication of a separate Activity "About" (It didn't work - I understand how to go to the URL, but I don't understand how to access the Activity)
2. Create a separate layout and register it on the PreferenceScreen via android:layout (It didn't work out - it gives an error)
3. To catch a click on Preference and send it to the desired Activity - it swears at the startActivity line, as I understand it because of "this", but I still don't understand what exactly needs to be specified in this case.
Third option code:

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static class GeneralPreferenceFragment extends PreferenceFragment {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.preferences);

            Preference about = (Preference) findPreference("about");

            about.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
            {
                public boolean onPreferenceClick(Preference pref)
                {
                    startActivity(new Intent(this, InfoActivity.class));
                    return true;
                }
            });
        }

    }

The question is not specifically in my code, but how can this be done correctly? And then I’ll throw the code in the comment when I try to do it the right way.
I just published it and immediately decided - getActivity(), of course... in the third version!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2017-05-24
@LockUs

Yandex.Metro does not use PreferenceFragment. We consider this api to be inconvenient and inflexible. A regular fragment with regular views is used. And, in general, it is justified.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question