I want an alert dialog box to pop up after I click a button to have a seek bar so that the person can change the value from 1-48. I\'ve made a custom xml that has a seek bar
Yep builder.setView(View v);
here is how you can use it.
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.yourLayoutId, (ViewGroup) findViewById(R.id.yourLayoutRoot));
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setView(layout);
AlertDialog alertDialog = builder.create();
alertDialog.show();
SeekBar sb = (SeekBar)layout.findViewById(R.id.yourSeekBar);
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
//Do something here with new value
}
});
Edit: Added progressListener to sample code. Do note that you cannot get a reference to your SeekBar until after you call alertDialog.show(), if the SeekBar is not being shown findViewById() will return null. Also note that you must use layout.findViewById();
because the SeekBar is a child of the RelativeLayout that 'layout' is a reference to.
//This is the code you seek!
public void ShowDialog(){
final AlertDialog.Builder popDialog = new AlertDialog.Builder(this);
final SeekBar seek = new SeekBar(this);
seek.setMax(255);
seek.setKeyProgressIncrement(1);
popDialog.setIcon(android.R.drawable.btn_star_big_on);
popDialog.setTitle("Please Select Into Your Desired Brightness ");
popDialog.setView(seek);
seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
txtView.setText("Value of : " + progress);
}
Or you can look on this tutorial