Hi,
I have a preference screen where a edit text brings up a spinner, the
result from the spinner needs to get to the edit text on the
preference screen and the value from the edit text needs to then get
back to the main activity.  I can get the value from a straight edit
text to the main activity but I cannot figure out how to get the
spinner choice to the edit field.
(disclaimer, the bulk of this is from an example project that I am
trying to use to learn how to do this).
The relevant porton of the main.xml
        <TableRow>
                <TextView
                        android:text="Edit TEXT:"
                        android:paddingRight="5dip"/>
                <TextView android:id="@+id/edittext"/>
        </TableRow>

I have a preferences.xml in the /res/xml folder...
<PreferenceScreen
        xmlns:android="http://schemas.android.com/apk/res/android";>
        <EditTextPreference
                android:key="edit_text"
                android:title="Edit Text Preference"
                android:dialogLayout="@layout/spinner"
                android:summary="What to do?"/>
</PreferenceScreen>

I also have a spinner.xml in the /layout folder
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Spinner
        android:id="@+id/spinner"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:width="200dp"
                android:entries="@array/edit_text_array"
                />
</LinearLayout>

There are two activities.  The first is PrefsActivity
package com.Prefs;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class PrefsActivity extends Activity {
    /** Called when the activity is first created. */
        private static final int EDIT_ID = Menu.FIRST+3;

        private TextView check_box=null;
        private TextView edit_text=null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        check_box=(TextView) findViewById(R.id.checkbox1);
        edit_text=(TextView) findViewById(R.id.edittext);

    }

    public void onResume() {
        super.onResume();

        SharedPreferences
prefs=PreferenceManager.getDefaultSharedPreferences(this);
        check_box.setText(new Boolean(prefs.getBoolean("check_box",
false)).toString());
        edit_text.setText(prefs.getString("edit_text", ""));
        //spinner.setText(prefs.getString("spinner", ""));
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(Menu.NONE, EDIT_ID, Menu.NONE, "Edit Prefs")
                .setIcon(R.drawable.icon)
                .setAlphabeticShortcut('e');

        return(super.onCreateOptionsMenu(menu));
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case EDIT_ID:
                startActivity(new Intent(this, EditPreferences.class));
                return(true);
        }
        return(super.onOptionsItemSelected(item));
    }
}

and finally the EditPreferences activity.
package com.Prefs;


import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.widget.TextView;

public class EditPreferences extends PreferenceActivity {
        private TextView spinner=null;
        private TextView edit_text=null;
        @Override

        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                spinner=(TextView) findViewById(R.id.spinner);
                addPreferencesFromResource(R.xml.preferences);

        }

        public void onResume() {
                super.onResume();
        }
}

What I was thinking was that the spinner needed to feed the result to
the edittext on the preferences before the edittext on the preferences
could feed it to the one on the PrefsActivity activity.
Long story short, what am I doing wrong and what should I do on this?
I'm a little brained out on this after staring at it and trying
everything my limited understanding could think of.
Thanks in advance.
Erik Wagner

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to