I am creating a brightness control dialog. However the problem I am having is that when I put textview then seekbar it causes this error:
android.widget.SeekBar cannot be cast to android.widget.TextView
For some reason it seems to work when the positioning on .xml follows seekbar then textview.
Here is some code:
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);
}
});
Try cleaning your project (Project > Clean from Eclipse or ant clean
from the command line), and see if that clears up your problem. Sometimes the build system gets a bit out of sync with itself in terms of the R
values, and this sort of error is one of the symptoms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With