小编Moh*_*war的帖子

如何在Android Switch中添加第三个状态?

我正在尝试编写一个Android代码来为Android Switch创建三种状态.三态表示ON - 默认 - OFF.

当我打开我的应用程序时,Switch将处于默认模式,按钮将位于中心.当我将开关拖到左侧时,状态将变为ON,当我将拖动到右侧时,状态将变为OFF.

在Android Switch中,我们有两个状态ON/OFF.我无法找到任何将第三种状态添加到交换机的技术.

如何在Android Switch中添加第三个状态?

android switch-statement

5
推荐指数
1
解决办法
3318
查看次数

node.js:使用vash呈现错误

我在node.js中使用vash收到渲染错误.我真的很想知道问题是什么.下面是错误和导致错误的代码.

TypeError: Problem while rendering template at line 4, character 2.
 Original message: object is not a function. Context: 2 |
 @html.block('body', function(model){ 3 | <p>@model.title </p> > 4 |
 }); 5 | }); 6 | 7 | at helpers.extend.model
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2213:4)
 at Object.vash.loadFile
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2072:10)
 at helpers.extend
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2190:8)
 at eval (eval at <anonymous>
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:1820:24),
 <anonymous>:7:21) at vash.link.linked
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:1860:12)
 at vash.renderFile
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2082:21)
 at Object.vash.loadFile
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2070:10)
 at View.vash.renderFile [as engine]
 (C:\Users\user009\Dropbox\cpp\node_modules\vash\build\vash.js:2078:8)
 at View.render
 (C:\Users\user009\Dropbox\cpp\node_modules\express\lib\view.js:76:8)
 at Function.app.render
 (C:\Users\user009\Dropbox\cpp\node_modules\express\lib\application.js:502:10)
Run Code Online (Sandbox Code Playgroud)

路由器:

app.get("/", function (request, response) { …
Run Code Online (Sandbox Code Playgroud)

rendering viewengine node.js vash

4
推荐指数
1
解决办法
1496
查看次数

雪碧图像水平还是垂直?

我正在为我的项目使用Sprite图像.我们应该遵循横向还是纵向?我的意思是说并排(占据更多宽度)或一个再见(占据更多高度).

在精灵中添加图像是否有任何宽度/高度限制?是否包含任何装载概念?

css css-sprites

4
推荐指数
2
解决办法
2738
查看次数

3
推荐指数
1
解决办法
4297
查看次数

为什么未经检查的异常未被java编译器检查?

我的问题更多的是关于设计,java编译器强制我们捕获一个已检查的异常(例如FileNotFoundException)但不强制我们捕获未经检查的异常(例如NullPointerException).我想了解原因,为什么编译器是这样设计的?

解释未经检查的例外 - 争议表明它是为提高可读性而完成的.

不捕获运行时异常不是一个很大的代价吗?

编辑:按成本我的意思是,在实时环境中而不是在编译时本身获取运行时异常.如果在编译期间处理此类异常,则不存在错误泄漏的可能性.修复错误的成本随着检测到的相位延迟而增加.

java exception

3
推荐指数
1
解决办法
3125
查看次数

在PHP中获取禁用文本框的值

我从用户那里得到两个数字,然后在禁用的文本框中显示它们的总和.我也将输入存储在我的数据库中.

一切正常.我可以将number1和number2传递给我的数据库但是我无法将sum传递给db.我花了太多时间自己解决这个问题,但没有运气.

你能查一下我的代码,让我知道我在这里缺少什么吗?我想要的是将总和存储到我的数据库中.

所以这是我的形式:

    <p>Enter number1:</p>
    <input id="number1" name="number1"/>

    <p>Enter number2:</p>
    <input id="number2" name="number2"/>

    <p>Sum</p>
    <input id="sum" name="sum" disabled="disabled"/>
Run Code Online (Sandbox Code Playgroud)

这是我的脚本:

    var sum = (number1 + number2);
    $('#sum').val(sum);
Run Code Online (Sandbox Code Playgroud)

这是我的PHP代码:

    <?php
    ..connection info here..
    $number1 = $_POST['number1']; 
    $number2 = $_POST['number2']; 
    $sum = $_POST['sum']; 
    $stmt = $mysqli->prepare("INSERT INTO mytable VALUES( '$number1', '$number2', '$sum')");
    if($stmt)
    echo "Done.";
    else
    echo "Error.";

    $stmt->execute();
    $stmt->close();
    $mysqli->close();
    ?>
Run Code Online (Sandbox Code Playgroud)

html javascript php jquery

3
推荐指数
2
解决办法
4816
查看次数

Javac是否与平台无关

我是Java的新手,有人澄清我对平台独立性的疑虑,我知道Java是一种独立于平台的语言,而JVM是依赖于平台的,但是Java编译器平台是独立的吗?

java javac

3
推荐指数
1
解决办法
2040
查看次数

重定向到另一个url后执行js代码

我有一个如下页面,当用户单击 Go href 时,它将重定向到另一个页面。我想在页面完全加载后在重定向页面上进行一些 JS 操作,但这样做遇到麻烦。

我尝试通过将所有 JS 操作语句放入 setTimeout 函数来实现此目的,但似乎在加载重定向页面后这些语句不会执行。在下面的示例中,alert('in settimeout') 未执行。

你能告诉我如何实现这一目标吗?谢谢!

<!DOCTYPE html>
<html>
<body>
<a href="#" onclick="foo()">Go</a>

<script>
function foo(){
  setTimeout(function (){
    alert('in settimeout'); // **this will not be executed.**
    //js manipulations here ... 
  }, 5000);
  window.location.replace('http://onlineapp.ws');
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript redirect

3
推荐指数
1
解决办法
7471
查看次数

Angular 5:预检的响应具有无效的HTTP状态代码403

当我向服务器发送POST请求时,我收到一个错误:

Failed to load http://localhost:8181/test: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 403.
Run Code Online (Sandbox Code Playgroud)

后端是用Java Spring编写的.我创建测试的方法:

createTest() {
    const body = JSON.stringify({
      'description': 'grtogjoritjhio',
      'passingTime': 30,
      'title': 'hoijyhoit'
    });

    const httpOptions = {
      headers: new HttpHeaders({
          'Content-Type': 'application/json',
          'Accept': 'application/json'
        }
      )
    };

    return this._http.post(`${this._config.API_URLS.test}`, body, httpOptions)
      .subscribe(res => {
        console.log(res );
      }, error => {
        console.log(error); …
Run Code Online (Sandbox Code Playgroud)

java spring cors http-status-code-403 angular5

3
推荐指数
1
解决办法
1万
查看次数

将局部变量转换为类变量的函数

如何将这两个函数添加到android studio,将现有(不可访问)变量转换为私有/公共?截图是伪造的而不是真实的,但这是我的问题的目的.

要将局部变量转换为私有/公共,我必须执行以下步骤:
- 剪切[variable-class] [variable-name]
- 写入[private/public]
- 将光标位置更改为类头
- 粘贴[variable-class] [variable-name]
- 复制[variable-name]
- 将光标位置更改为类方法
- 粘贴[variable-name]

在此输入图像描述

android-studio

2
推荐指数
2
解决办法
2098
查看次数