0

私はandroidでソフトキーボードを開発しようとしています.inputmethodeServiseを拡張するクラスでXmlファイルを使用して、それをkeyboardViewの属性として作成したいと考えています.レイアウトリソース(input1.xml、input2.xml、 input3.xml) を呼び出し、これらの xml を優先的に呼び出します。

     @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
                String key) {
            if(key.equals("textColor"))
            {
             String selectedColor = sharedPreferences.getString(key, "green");
             if (selectedColor.equals("red"))
             {

                 sw=1;

     }

             if (selectedColor.equals("blue"))
             {

                 sw=2;
                  }
                if (selectedColor.equals(" yellow"))
             {

                 sw=3;
                  }
              }

        }

xmlファイルを選択する方法は次のとおりです。

int sw;

 @Override public void onCreate() {
         prefs = PreferenceManager.getDefaultSharedPreferences(this);
         prefs.registerOnSharedPreferenceChangeListener(this);

        super.onCreate();

        switch(sw)
        { case 1:
 mInputView = (LatinKeyboardView) getLayoutInflater().inflate(R.layout.input1, null);
             break;
        case 2:
    mInputView = (LatinKeyboardView) getLayoutInflater().inflate(R.layout.input1, null);
      break;
    case 3: mInputView = (LatinKeyboardView) getLayoutInflater().inflate(R.layout.input2, null);
break
default:
 mInputView = (LatinKeyboardView) getLayoutInflater().inflate(R.layout.input, null);

        }
    }

しかし、prefrnceActivitey からアイテムを選択すると、xml ファイルは変更されません。これは、変数 (sw) が更新されないことを意味します。どうすれば好みで (sw) 更新できますか?? 誰か私の問題に従ってください

4

1 に答える 1