Android development Preference usage, androidpreference

Source: Internet
Author: User

Android development Preference usage, androidpreference

1. Preference is a base class provided by androidSDK from API1. It is used to display the interface to users.

2. When Preference is used to display an activity, this activity must inherit the Preferenceactivity and implement addPreferencesFromResource (R. xml. main) load the layout file. The layout file needs to create a new xml folder under the res folder. Create an xml file. 3. There are three labels in the layout file: PreferenceScreen root node PreferenceCategory classification node Preference subnode
<?xml version="1.0" encoding="utf-8"?><PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >    <PreferenceCategory android:title="@string/general" >        <Preference android:title="@string/properties" />        <Preference android:title="@string/attach" />        <Preference android:title="@string/left_and_right" />        <Preference android:title="@string/changing_fragments" />        <Preference android:title="@string/responsive_ui" />        <Preference android:title="@string/viewpager" />    </PreferenceCategory>    <PreferenceCategory android:title="@string/title_bar" >        <Preference android:title="@string/title_bar_slide" />        <Preference android:title="@string/title_bar_content" />    </PreferenceCategory>    <PreferenceCategory android:title="@string/animations" >        <Preference android:title="@string/anim_zoom" />        <Preference android:title="@string/anim_scale" />        <Preference android:title="@string/anim_slide" />    </PreferenceCategory></PreferenceScreen>

4. Rewrite the onPreferenceTreeClick method to implement listening.

    @Override    public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference pref) {        Class<?> cls = null;        String title = pref.getTitle().toString();        if (title.equals(getString(R.string.properties))) {            cls = PropertiesActivity.class;            } else if (title.equals(getString(R.string.attach))) {            cls = AttachExample.class;        } else if (title.equals(getString(R.string.changing_fragments))) {            cls = FragmentChangeActivity.class;        } else if (title.equals(getString(R.string.left_and_right))) {            cls = LeftAndRightActivity.class;        } else if (title.equals(getString(R.string.responsive_ui))) {            cls = ResponsiveUIActivity.class;        } else if (title.equals(getString(R.string.viewpager))) {            cls = ViewPagerActivity.class;        } else if (title.equals(getString(R.string.title_bar_slide))) {            cls = SlidingTitleBar.class;        } else if (title.equals(getString(R.string.title_bar_content))) {            cls = SlidingContent.class;        } else if (title.equals(getString(R.string.anim_zoom))) {            cls = CustomZoomAnimation.class;        } else if (title.equals(getString(R.string.anim_scale))) {            cls = CustomScaleAnimation.class;        } else if (title.equals(getString(R.string.anim_slide))) {            cls = CustomSlideAnimation.class;        }        Intent intent = new Intent(this, cls);        startActivity(intent);        return true;    }

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.