Android对话框帮助!

时间:2011-06-21 13:37:39

标签: android

我有一个问题,希望你们能帮助我!

此代码创建一个对话框,并在对话框中显示一个按钮和一个搜索栏。

当我设置seekbar setonseekbarchangelistener时,我得到一个Nullpointerexception错误。而且我不知道为什么! (取消注释seekbar.setOnSeekBarChangeListener(this)以获取错误)

    public class seekActivity extends Activity implements OnClickListener,   OnSeekBarChangeListener  {
       SeekBar seekbar;
        Button button;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //set up main content view
        setContentView(R.layout.main);
        //this button will show the dialog
        Button button1main = (Button) findViewById(R.id.Button01main);


        button1main.setOnClickListener(this);

    }
        public void onClick(View v) {
                //set up dialog
                Dialog dialog = new Dialog(this);
                dialog.setContentView(R.layout.maindialog);
                dialog.setTitle("This is my custom dialog box");
                dialog.setCancelable(true);
                 button = (Button) dialog.findViewById(R.id.Button01);
                seekbar = (SeekBar) findViewById(R.id.seekBar1);
                //seekbar.setOnSeekBarChangeListener(this);
                dialog.show();

        }
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            // TODO Auto-generated method stub

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

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

        };


            }

1 个答案:

答案 0 :(得分:3)

使用这段代码,按ID找到seekBar1。

seekbar = (SeekBar) dialog.findViewById(R.id.seekBar1);