我在主activity中设置了一个带有三个选项卡的交换卡,第三个选项卡中有一个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("set")
.setView(dialogView)
.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "set success!", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("cancel", 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 指针错误。
对话框.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="reminder the time"
/>
<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="remind way"
/>
<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="ring"
/>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="shake"
/>
</LinearLayout>
</LinearLayout>