2012-03-05 65 views
5

我正在創建一個亮度控制對話框。但是我遇到的問題是,當我把TextView的那麼搜索條它會導致這個錯誤:android.widget.SeekBar不能轉換爲android.widget.TextView

android.widget.SeekBar cannot be cast to android.widget.TextView

出於某種原因,似乎當.XML定位如下搜索條,然後TextView的工作。

下面是一些代碼:

LayoutInflater li_brightness = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE); 
      View v_brightness = li_brightness.inflate(R.layout.options_dialog_brightness, (ViewGroup)findViewById(R.id.ll_brightness_layout)); 
      bright_textView = (TextView)v_brightness.findViewById(R.id.brightness_text); 
      brightBar = (SeekBar)v_brightness.findViewById(R.id.seekbar_brightness); 
      confirm_brightness = (Button)v_brightness.findViewById(R.id.button_brightness); 



      cResolver = getContentResolver(); 

      window = getWindow(); 

      brightBar.setMax(100); 
      brightBar.setProgress(50); 
      brightBar.setKeyProgressIncrement(1); 

      bright_textView.setText("50".toString()); 


      brightBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { 

       public void onStopTrackingTouch(SeekBar seekBar) { 
        // TODO Auto-generated method stub 

       } 

       public void onStartTrackingTouch(SeekBar seekBar) { 
        // TODO Auto-generated method stub 

       } 

       public void onProgressChanged(SeekBar seekBar, int progress, 
         boolean fromUser) { 
        // TODO Auto-generated method stub 
        float BackLightValue = (float)progress/100; 
        if(BackLightValue <= 0){ 
         bright_textView.setText(String.valueOf(BackLightValue)); 
        } 


         WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); 
         layoutParams.screenBrightness = BackLightValue; 
         getWindow().setAttributes(layoutParams); 
       } 
      }); 
+0

添加logcat和XML,我認爲但不是很確定,由於您的id來自XML佈局文件的問題您將Textview的id提供給Seekbar檢查它! – 2012-03-05 14:25:43

回答

10

嘗試清潔您的項目(Project>從Eclipse的清潔或ant clean命令行),並看看是否能清除了你的問題。有時構建系統在R值方面與自身有些不同步,並且這種錯誤是其中一種症狀。

+0

你完全正確。出於某種原因,我在沒有工作之前嘗試過。 – wesdfgfgd 2012-03-05 15:44:36

相關問題