我的应用程序有问题,如果用户快速多次单击该按钮,那么即使我按下该按钮的对话框消失,也会生成多个事件
通过在单击按钮时将布尔变量设置为标志,我知道了一种解决方案,因此可以阻止将来的点击,直到关闭对话框.但是我有很多按钮,每次按钮都必须这样做,因为每个按钮似乎都是一种矫枉过正.在Android(或许是一些更智能的解决方案)中,没有其他方法只允许每个按钮点击生成事件动作吗?
更糟糕的是,即使处理第一个操作,多个快速点击似乎也会生成多个事件操作,因此如果我想在第一个单击处理方法中禁用该按钮,则队列中已存在等待处理的事件操作!
请帮忙谢谢
我在视图中使用多个按钮,每个按钮都会显示自己的弹出页面.同时单击多个按钮时,它一次转到不同的弹出页面.
我创建了一个包含3个按钮的示例内容页面(每个按钮都转到不同的弹出页面)来演示此问题:
XAML页面:
<ContentPage.Content>
<AbsoluteLayout>
<!-- button 1 -->
<Button x:Name="button1" Text="Button 1"
BackgroundColor="White" Clicked="Button1Clicked"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0.5, 0.3, 0.5, 0.1"/>
<!-- button 2 -->
<Button x:Name="button2" Text="Button 2"
BackgroundColor="White" Clicked="Button2Clicked"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0.5, 0.5, 0.5, 0.1"/>
<!-- button 3 -->
<Button x:Name="button3" Text="Button 3"
BackgroundColor="White" Clicked="Button3Clicked"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0.5, 0.7, 0.5, 0.1"/>
<!-- popup page 1 -->
<AbsoluteLayout x:Name="page1" BackgroundColor="#7f000000" IsVisible="false"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0.5, 0.5, 1.0, 1.0">
<BoxView Color="Red"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0.5, 0.5, 0.75, 0.3"/>
<Label Text="Button 1 clicked" TextColor="White"
HorizontalTextAlignment="Center"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0.5, 0.45, …Run Code Online (Sandbox Code Playgroud) 我在最近正在进行的项目中使用Google的PlaceAutoCompleteFragment.当我非常快速地点击PlaceAutoCompleteFragment时,它会在我的应用上打开多个叠加层,这真的很烦人.如何防止它打开多个叠加层?我的片段代码如下:
if (autocompleteFragment == null) {
autocompleteFragment = (PlaceAutocompleteFragment)getFragmentManager().findFragmentById(R.id.place_autocompletehome_fragment);
}
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
try {
Log.i("esty", "Place: " + place.getName());
} catch (Exception e) {
Log.e("esty", "Error: " + e.getMessage());
}
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.e("esty", "An error occurred: " + status);
}
});
Run Code Online (Sandbox Code Playgroud)