Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin 如何捕获并保持ImageButton状态以更改为第三个图像?_Xamarin_Xamarin.android - Fatal编程技术网

Xamarin 如何捕获并保持ImageButton状态以更改为第三个图像?

Xamarin 如何捕获并保持ImageButton状态以更改为第三个图像?,xamarin,xamarin.android,Xamarin,Xamarin.android,当前有以下功能-按Ston,图像将变为Ston 启动和停止功能代码: button.Touch += (object sender, View.TouchEventArgs e) => { if (e.Event.Action == MotionEventActions.ButtonPress) { } }; 如果上述代码中有,则ok符号可能不会显示为附加的 如何按住停止标志,然后

当前有以下功能-按
Ston
,图像将变为
Ston

启动和停止功能代码:

button.Touch += (object sender, View.TouchEventArgs e) =>
        {
            if (e.Event.Action == MotionEventActions.ButtonPress)
            {

            }

        };
如果上述代码中有,则ok符号可能不会显示为附加的


如何按住停止标志,然后再次单击它以获得“确定”标志?

您可以更改
按钮。触按事件可切换到其他类似以下功能:

button.Touch += (object sender, View.TouchEventArgs e) => {
    if (e.Event.Action == MotionEventActions.ButtonPress)
    {
        button.SetImageResource(Resource.Drawable.ic_start);
    }
    else if (e.Event.Action == MotionEventActions.Down)
    {
        button.SetImageResource(Resource.Drawable.ic_stop);
        button.Touch += (object stopButtonSender, View.TouchEventArgs stopButtonEventArgs) => {

            // Your logic for showing OK sign
        };
    }
};
确保取消订阅了上一个事件,以防止内存泄漏

button.Touch -= your_function;

您可以更改
按钮。将
事件触摸到以下其他功能:

button.Touch += (object sender, View.TouchEventArgs e) => {
    if (e.Event.Action == MotionEventActions.ButtonPress)
    {
        button.SetImageResource(Resource.Drawable.ic_start);
    }
    else if (e.Event.Action == MotionEventActions.Down)
    {
        button.SetImageResource(Resource.Drawable.ic_stop);
        button.Touch += (object stopButtonSender, View.TouchEventArgs stopButtonEventArgs) => {

            // Your logic for showing OK sign
        };
    }
};
确保取消订阅了上一个事件,以防止内存泄漏

button.Touch -= your_function;
如何捕获并保持ImageButton状态以更改为第三个图像

您可以使用一个变量:

int i = 1;
每次单击
ImageButton
时更改其值:

bt_im.Click += (sender, e) => 
{
    if (i % 3 == 0)
    {
        bt_im.SetBackgroundResource(Resource.Drawable.ic_stop);
        i++;
        //Next time your ImageButton was clicked will set a ic_start image.
    }
    else if(i % 3 == 1)
    {
        bt_im.SetBackgroundResource(Resource.Drawable.ic_OK);
        i++;
    }
    else if (i % 3 == 2)
    {
        bt_im.SetBackgroundResource(Resource.Drawable.ic_start);
        i++;
    }

};
如何捕获并保持ImageButton状态以更改为第三个图像

您可以使用一个变量:

int i = 1;
每次单击
ImageButton
时更改其值:

bt_im.Click += (sender, e) => 
{
    if (i % 3 == 0)
    {
        bt_im.SetBackgroundResource(Resource.Drawable.ic_stop);
        i++;
        //Next time your ImageButton was clicked will set a ic_start image.
    }
    else if(i % 3 == 1)
    {
        bt_im.SetBackgroundResource(Resource.Drawable.ic_OK);
        i++;
    }
    else if (i % 3 == 2)
    {
        bt_im.SetBackgroundResource(Resource.Drawable.ic_start);
        i++;
    }

};

我修改了密码。发送方和e在第二次
Touch+=
声明时声明在同一范围内。基本上,将发件人更改为发件人2,将e更改为e2可以解决此问题。请确保您正在检查
MotionEventActions。在逻辑中按按钮以显示OK符号。我对代码进行了更改。发送方和e在第二次
Touch+=
声明时声明在同一范围内。基本上,将发送者更改为发送者2,将e更改为e2可以解决此问题。请确保您正在检查
MotionEventActions。按钮按逻辑中的
,以显示OK符号。@W4y,“快速单击停止按钮”是什么意思?@W4y,您想要什么效果?请再详细一点。@W4y,我已经更新了我的答案,这是你想要的效果吗?不,对不起,上面的要求是另一个。我所描述的与解决方案中第二个
的行为不同。@W4y,“快速点击停止按钮”是什么意思?@W4y,你想要什么效果?请再详细一点。@W4y,我已经更新了我的答案,这是你想要的效果吗?不,对不起,上面的要求是另一个。我所描述的与解决方案中第二个
else if
的行为不同。