- Java code
我在主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错误
------解决方案--------------------
timePicker = (TimePicker) this.findViewById(R.id.TimePicker1);
this换成dialogView,