我有一个AlertDialog弹出DatePicker和TimePicker就可以了。 AlertDialog很长,所以你必须向下滚动才能填满所有内容。但是,每次我点击某个地方时,视图都会自动跳回到AlertDialog的顶部,这样就无法安静地点击Timeicker。
每次点击某些内容时,有没有办法阻止它自动向上滚动?
以下是代码:
private void AddEventDialog(ListView listview, Marker marker, ArrayAdapter<string> adapter)
{
TextView name_tv = new TextView(this);
EditText name_et = new EditText(this);
TextView start_date_tv = new TextView(this);
TextView end_date_tv = new TextView(this);
DatePicker start_date_picker = new DatePicker(this);
DatePicker end_date_picker = new DatePicker(this);
TimePicker start_time_picker = new TimePicker(this);
TimePicker end_time_picker = new TimePicker(this);
LinearLayout ll = new LinearLayout(this);
ScrollView sv = new ScrollView(this);
AlertDialog.Builder ad = new AlertDialog.Builder(this);
name_tv.Text = "Nom :";
name_tv.TextSize = 18.0f;
start_date_tv.Text = "Début :";
start_date_tv.TextSize = 18.0f;
end_date_tv.Text = "Fin :";
end_date_tv.TextSize = 18.0f;
ll.Orientation = Orientation.Vertical;
ll.SetPadding(30, 0, 30, 0);
ll.CanScrollVertically(1);
ll.AddView(name_tv);
ll.AddView(name_et);
ll.AddView(start_date_tv);
ll.AddView(start_date_picker);
ll.AddView(start_time_picker);
ll.AddView(end_date_tv);
ll.AddView(end_date_picker);
ll.AddView(end_time_picker);
sv.AddView(ll);
ad.SetTitle("Ajout d'un événement");
ad.SetView(sv);
ad.SetPositiveButton("Ajouter", (senderAlert, args) => {
ToastUser("Événement ajouté !", ToastLength.Long);
DateTime dts = start_date_picker.DateTime.AddHours(start_time_picker.Hour);
dts = start_date_picker.DateTime.AddMinutes(start_time_picker.Minute);
DateTime dte = end_date_picker.DateTime.AddHours(end_time_picker.Hour);
dte = end_date_picker.DateTime.AddMinutes(end_time_picker.Minute);
EventCreation(name_et.Text, GetPlaceFromMarker(marker).Id, marker.Snippet, start_date_picker.DateTime, end_date_picker.DateTime);
adapter.Add(name_et.Text);
listview.Adapter = adapter;
dialog_child.Dismiss();
ManageEventsDialog(marker);
});
ad.SetNegativeButton("Annuler", (senderAlert, args) => {
});
ad.Show();
}
答案 0 :(得分:0)
我想这是因为您的编辑文本,您的编辑文本总是开始焦点,尝试首先禁用它: 在Manifest on欲望活动中设置此
机器人:windowSoftInputMode = “stateHidden”