Android dialog not showing up
I have a textview and once I click on it will open a dialog 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 click on the dialog.
Do you have any suggestion? TIA.
No comments:
Post a Comment