我正在创建一个亮度控制对话框。但是我遇到的问题是当我把textview然后搜索到它时会导致这个错误:
android.widget.SeekBar无法强制转换为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 :(得分:10)
尝试清理项目(项目&gt;从Eclipse中清除或从命令行清除ant clean
),看看是否能解决您的问题。有时构建系统在R
值方面与自身有点不同步,这种错误就是其中一种症状。