Should I create activity for each screen?

I'll start with an example ... If you go to Settings> Applications> Manage Applications, a new screen will open with a list of installed applications: if you click on any application in the list, it will open a new screen containing information about the application.

Well, some of the settings of my application must be managed through a list, and this list should behave like the example above. I have already created PreferenceActivitywith some categories, each of which has some elements: when I click on one of these elements, I would like it to open a new screen where new data is placed in the list, as well as the list of applications of the above example. Moreover, when I click on any entry in this list, it will open a new screen to set some data.

How do I proceed? Should I create activity for each screen?

+3
source share
5 answers

Android , " - , , ". , . Honeycomb , , , Android.

+3

, , ( ) ,

A Activity B, startActivityForResult :

"", , , , .

API , , .

+3

, , .

ListActivity, , , .

+2

, , , . , , : , , , preferenceClickListener, . , , , .

!

:

?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
    android:title="Personal"
    android:key="personal_category">
    <Preference
        android:key="birth"
        android:title="Birth"
        android:summary="Choose your birthday"/> 
    <PreferenceScreen 
        android:key="height_imp"
        android:title="Height"
        android:summary="Enter your height">
        <EditTextPreference
            android:key="foot"
            android:title="Foot" 
            android:summary="foot"
            android:numeric="integer"
            android:dialogTitle="Foot"/>
        <EditTextPreference
            android:key="inch"
            android:title="Inch" 
            android:summary="inch"
            android:numeric="integer"
            android:dialogTitle="Inch"/>
    </PreferenceScreen>
    <EditTextPreference
        android:key="weight"
        android:title="Weight" 
        android:summary="Enter your weight"
        android:numeric="integer"
        android:dialogTitle="Weight"/>    
</PreferenceCategory>
</PreferenceScreen>

! , PreferenceScreen .., , , Activity. Preference onPreferenceClick:

@Override
public boolean onPreferenceClick(Preference preference) {
    if(preference == birth){
        startActivity(new Intent(getBaseContext(), Birth.class));
    }
    if(preference == height_imp){
        PreferenceScreen a = (PreferenceScreen) preference;
        a.getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
        return false;
    }
    return true;
}

- , preferenceClickListener: height_imp = (PreferenceScreen)getPreferenceScreen().findPreference("height_imp"); height_imp.setOnPreferenceClickListener(this);

+2

... ... ... ... , ... ... ... ... . , .. ( [ , ] ..)

+1

All Articles