我在主activity里面设置了有三个tab的切换卡,在第三个tab里面是个ListView,单击ListView会弹出时间选择对话框
public void onSetWarn(){
LayoutInflater factoryInflater = LayoutInflater.from(MainActivity.this);
final View dialogView = factoryInflater.inflate(R.layout.dialog, null);
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setTitle("设置")
.setView(dialogView)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "设置成功!", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

}
}).create();
/*
timePicker = (TimePicker) this.findViewById(R.id.TimePicker1);
timePicker.setIs24HourView(true);
*/
dialog.show();
}我到底该把timePicker = (TimePicker) this.findViewById(R.id.TimePicker1);
timePicker.setIs24HourView(true);
这段代码放在哪呢? 我试了好几个地方都是NULL pointer错误

解决方案 »

  1.   

    dialog.xml文件如下:<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="提醒时间"
            />
        <TimePicker 
            android:id="@+id/TimePicker1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
          <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="提醒方式"
            />
          <LinearLayout 
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              >
          <CheckBox 
              android:id="@+id/checkBox1"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="铃声"
              />
          <CheckBox 
              android:id="@+id/checkBox2"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="震动"
              />
          </LinearLayout>
    </LinearLayout>
      

  2.   

    timePicker = (TimePicker) this.findViewById(R.id.TimePicker1);
    this换成dialogView,