当我尝试从对话框中获取seekbar vue时,我得到一个零

时间:2014-01-21 23:48:23

标签: android

我的对话框上有一个搜索栏。当我尝试获取对话框中的Seekbar viw时,我得到一个null。使用搜索条绘制对话框,您可以来回移动滑块

代码:

void StartSound() {
    // custom dialog
    dialog = new Dialog(this);
    dialog.setContentView(R.layout.dialog_sound);
    dialog.setTitle("Information");
    // bar is always null
    bar = (SeekBar)findViewById(R.id.seekBar1); // make
    // bar.setOnSeekBarChangeListener(this);
    // bar.setProgress( 10 );
    View dialogButton = dialog.findViewById(R.id.ok );
    dialogButton.setOnClickListener(this);
    dialog.show();
}

xml文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff29245c"
    android:orientation="vertical" >

    <!-- for graphic background use  android:background="@drawable/background"  --> 

    <SeekBar android:id="@+id/seekBar1" 
         android:max="100" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" >
    </SeekBar>

  <LinearLayout
        android:id="@+id/mainLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

  <Button
     android:id="@+id/ok"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:textSize="24px"
     android:text="OK"
     android:textStyle="bold"
     android:textColor="#ff0000ff"
     android:layout_marginLeft="24px"
     android:layout_marginRight="24px"
     android:layout_marginTop="24px"
     android:layout_marginBottom="12px" />      

  </LinearLayout>   
</LinearLayout>   

1 个答案:

答案 0 :(得分:0)

在显示对话框之前,您将获得搜索栏。那时候,它的视图没有被创建,因此在对话框的oncreateview方法完成之后,seekbar将为null,那么你可以获得搜索栏

相关问题