2010-01-27 45 views
0

我试图访问AlertDialog中的SeekBar。 我需要setOnSeekBarChangeListener(),或者访问SeekBar.getProgress()来获取它的值。我在哪里做这个?可能吗?如何通过LayoutInflater在AlertDialog中使用SeekBar设置OnSeekBarChangedListener

该对话框使用onOptionsItemSelected中的showDialog(id)显示。

以下代码用于onCreateDialog中创建具有包含SeekBar的自定义内容的AlertDialog。

case CALIBRATE_DIALOG_ID: { 
      // This example shows how to add a custom layout to an AlertDialog 
      LayoutInflater factory = LayoutInflater.from(this); 
      final View calibrateView = factory.inflate(R.layout.dlg_calibrate, null); 
      return new AlertDialog.Builder(this) 
       .setIcon(R.drawable.alert_dialog_icon) 
       .setTitle("Calibrate") 
       .setView(calibrateView) 
       .setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 

         //mSeekBar1 = (SeekBar) findViewById(R.id.SeekBar01); 
         //Toast.makeText(ctx, mSeekBar1.getProgress(), Toast.LENGTH_SHORT); 

        } 
       }) 
       .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 

         /* User clicked cancel so do some stuff */ 
        } 
       }) 
       .create(); 
     } 

我不能在主要活动onCreate中做到这一点; SeekBar尚未创建。我以为我可以在Ok Button的onClick处理程序中获取SeekBar.getProgress()值的句柄,但不能。

任何建议将是伟大的!

感谢

帕特里克

回答

4

你可以得到你通过你的calibrateView调用findViewById(),想必SeekBar

+0

那太明显了......再次感谢! – bugzy 2010-01-28 03:13:04

相关问题