解决Android dialog not showing up
2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址:https://cloud.tencent.com/act/cps/redirect?redirect=1062
2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址:https://www.aliyun.com/minisite/goods
创建对话框 一个对话框一般是一个出现在当前Activity之上的一个小窗口. 处于下面的Activity失去焦点, 对话框接受所有的用户交互. 对话框一般用于提示信息和与当
-1
I have a TextView
and once I click on it a dialog will open which utilizes a date and time picker as its view.
datetimepicker.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</DatePicker>
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TimePicker>
<LinearLayout
android:id="@+id/setcancel"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="SET" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CANCEL" />
</LinearLayout>
</LinearLayout>
and this the code for TextView.OnClickListener
final TextView startTime = (TextView) getActivity().findViewById(R.id.textView3);
startTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.datetimepicker);
dialog.setTitle("Set Date and Time");
Button set = (Button) dialog.findViewById(R.id.button1);
Button cancel = (Button) dialog.findViewById(R.id.button2);
final TimePicker tp = (TimePicker)dialog.findViewById(R.id.timePicker1);
tp.setCurrentHour(Calendar.HOUR_OF_DAY);
tp.setCurrentMinute(Calendar.MINUTE);
tp.setOnTimeChangedListener(new OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
hour = hourOfDay;
min = minute;
}
});
set.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startTime.setText(Integer.toString(hour)+ ";" + Integer.toString(min));
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
}
});
The problem is once I click on the TextView
it does nothing, I mean nothing happens and I wanted to set the text of the TextView
with the time set by the user once OK button is clicked on the dialog.
Do you have any suggestion? TIA.
android dialog|
this question edited Jul 8 '14 at 10:57 naXa 6,518 5 48 91 asked Aug 23 '13 at 13:50 RieJack 21 2 10
|
1 Answers
1
解决方法
You forgot to call
Dialog.show()
|
this answer edited Aug 23 '13 at 14:11 pb2q 39.5k 12 98 120 answered Aug 23 '13 at 13:51 Philipp Jahoda 29k 12 86 115 one last question when i click on the set button how can i set the text on the textview on button click? – RieJack Aug 23 '13 at 14:11 I think you are already doing that with this line: " startTime.setText(Integer.toString(hour)+ ";" + Integer.toString(min));"? – Philipp Jahoda Aug 23 '13 at 14:24 Thanks Phil.. I got it! – RieJack Aug 24 '13 at 13:13
|
相关阅读排行
- 1Android中LayoutInflater的使用
- 2Android 画布绘图
- 3Android Density(密度)
- 4Android网络连接判断与处理
- 5Android生成签名文件并用其对apk文件进行签名(Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]错误完美解决)