Android:我如何添加微调器到我的这个代码(我做的方式给出错误)

时间:2015-03-02 15:05:41

标签: android android-layout spinner onitemselectedlistener

String key,k[];
int index;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tarsos_dsp);
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);
     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.key, android.R.layout.simple_spinner_item);
     spinner.setAdapter(adapter);
     for(int i =0;i<=11;i++)
     {
           k = getResources().getStringArray(R.array.key);
           if(key.equals(k[i].toString()))
           {
               spinner.setSelection(i);
           }
     }

      spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
            index = arg0.getSelectedItemPosition();

                   // storing string resources into Array
                   k = getResources().getStringArray(R.array.key);

                    Toast.makeText(getBaseContext(), "You have selected key : " +k[index], 
                            Toast.LENGTH_SHORT).show();

            }

            public void onNothingSelected(AdapterView<?> arg0) {
                // do nothing

            }


        });
Thaat tht =  new Thaat();
    Bundle extras = getIntent().getExtras();
      if(extras !=null) {
          key= extras.getString("key");
          Toast.makeText(getApplicationContext(), key, Toast.LENGTH_SHORT).show();

      }

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }

    AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050,1024,0);            
    dispatcher.addAudioProcessor(new PitchProcessor(PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, new PitchDetectionHandler() {            
         @Override
            public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
                        final float pitchInHz = pitchDetectionResult.getPitch();
                        runOnUiThread(new Runnable() {                      

                            @Override
                             public void run() {
                                 TextView text = (TextView) findViewById(R.id.textView1);
                                 TextView d =(TextView) findViewById(R.id.textView2);

                             }
                       }

如果我添加它无效运行仍然会出错,如何使用意图添加来自上一个活动的默认值的微调器

0 个答案:

没有答案