-1

我在android中做了一个微调器

        public SiriusRadioPlayerActivity(){
    String[] arrayOfString = new String[4];
    arrayOfString[0] = "Kiskunfélegyháza HQ [160kbps MP3]";
    arrayOfString[1] = "Kiskunfélegyháza MQ [64kbps AAC]";
    arrayOfString[2] = "Kiskunmajsa HQ [160kbps MP3]";
    arrayOfString[3] = "Kiskunmajsa MQ [64kbps AAC]";
    this.items = arrayOfString;

     }        

这些是我要显示的字符串!

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initializeUIElements();

this.savszelesseg_port = localSharedPreferences.getString("savszelesseg_mentes",      "savszelesseg_port");
    this.savszelesseg_saved = this.savszelesseg_port;

在这里,我从我的偏好加载数据!

  final Spinner localSpinner = (Spinner)findViewById(R.id.savszelesseg);
    ArrayAdapter localArrayAdapter = new ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item, this.items);
    localArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    localSpinner.setAdapter(localArrayAdapter);

创建了微调器。并具有 en setOnItemSelectedListener 功能。

    localSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
    {
        public void onItemSelected(AdapterView parentView, View childView, int position, long id) 
        {
            if (!savszelesseg_port_modositva)
            {
              savszelesseg_beallitas = "Kiskunfélegyháza HQ [160kbps MP3]";
              savszelesseg_port_modositva = true;
            }
 if (savszelesseg_beallitas == "Kiskunfélegyháza HQ [160kbps MP3]")
            {
              savszelesseg_port = "8500/relay_911";

            }


        }
        public void onNothingSelected(AdapterView parentView) 
        {
        }
    });

问题是:如何将 savszelesseg_port 存储到我的 SharedPreferencies savszelesseg_mentes 默认值?因为我有一个计时器来定期检查网页,这取决于我从共享偏好中获得的值:

this.mWebView = ((WebView)findViewById(0x7f070035));
    this.mWebView.getSettings().setJavaScriptEnabled(true);
    new Timer().scheduleAtFixedRate(new TimerTask()
    {
      public void run()
      {
        if (SiriusRadioPlayerActivity.isOnline()){

            if (SiriusRadioPlayerActivity.this.mWebView_enabled == false){
                SiriusRadioPlayerActivity.this.mWebView.loadUrl("about:blank"); 
            }
            else
            {

                if(savszelesseg_port.contains("911")){
                 SiriusRadioPlayerActivity.this.mWebView.loadUrl("http://xxxx");    
                }
                if(savszelesseg_port.contains("882")){
                 SiriusRadioPlayerActivity.this.mWebView.loadUrl("http://xxx"); 
                }

                }

        }



      }}
    , this.delay, this.period);
    this.mWebView.setBackgroundColor(0);

本地共享首选项:

PreferenceManager.setDefaultValues(this, 0x7f040000, false);
    final SharedPreferences localSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    this.mWebView_enabled = localSharedPreferences.getBoolean("mWebView_enabled", true);
    this.savszelesseg_port = localSharedPreferences.getString("savszelesseg_mentes", "savszelesseg_port");
4

1 回答 1

0

行后:

          savszelesseg_port = "8500/relay_911";

你应该做 :

SharedPreferences.Editor editor = localSharedPreferences.edit();
editor.putString("savszelesseg_mentes", savszelesseg_port);
editor.commit();
于 2012-08-29T08:38:19.230 回答