小编use*_*293的帖子

如何从DialogFragment读取/写入首选项?

我想从DialogFragment中的首选项文件中读取.如果我这样做:

prefs = getSharedPreferences("numberPicker.preferences", 0);
Run Code Online (Sandbox Code Playgroud)

然后我得到一个编译时错误,因为getSharedReference是一个ContextWrapper方法但是DialogFragment不是ContextWrapper(我使用android.support.v4.app.DialogFragment来实现向后兼容).

或者,作为"解决方法",我使用在类InitSpel中创建的SharedPreferences对象prefs(它是一个FragmentActivity,因此是一个ContextWrapper)然后我没有得到错误(也没有在编译时也没有在运行时)但是值不是存储(下次启动应用程序时,值baan1和baan2仍为0).

怎么解决?

package mypackage;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

public class VraagBanenDialogFragment extends DialogFragment {

    private View v;
    private EditText editText1; 
    private EditText editText2; 
    //private ArrayList<Baan> baanNummers;
    private int[] oldBanen;
    private int[] currentBanen;
    private SharedPreferences prefs;

    /*  public VraagBanenDialogFragment(ArrayList<Baan> baanNummers) {
        this.baanNummers = baanNummers;
    }
*/
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = …
Run Code Online (Sandbox Code Playgroud)

android android-preferences android-alertdialog android-dialogfragment

7
推荐指数
1
解决办法
4053
查看次数

运行react-scripts后如何停止?

我用npm start来启动一个React应用程序,其中package.json中定义了start:

{
  "name": "testreactapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-scripts": "1.0.10"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}
Run Code Online (Sandbox Code Playgroud)

我现在想停止它,而不关闭终端。我怎么做?

尝试过:npm stop testrectapp,但是会抛出错误,需要脚本

然后尝试:使用脚本“ stop”运行npm run stop:“ pkill --signal SIGINT testreactapp”抛出错误“ pkill无法识别为命令”

编辑:在bash中运行ps显示: PID PPID PGID WINPID TTY UID STIME COMMAND 6652 1 6652 6652 ? 197612 19:52:49 /usr/bin/mintty 1092 1 1092 1092 ? 197612 Jul 25 /usr/bin/mintty 11092 6652 11092 10060 pty1 197612 …

javascript node.js reactjs pkill react-scripts

7
推荐指数
5
解决办法
2万
查看次数

Firebase更新或设置

将有关某人的帖子添加到Firebase数据库后,我想将该帖子的引用添加到此人.但是,该人可能已经存在,也可能不存在.

我有:

var ref = new Firebase("https://mydatabase.firebaseio.com/");
var _person = document.getElementById("Person").value;
var _remark = document.getElementById("Remark").value;

var postsRef = ref.child("remarks");
var newPostRef = postsRef.push({
    person: _person,
    remark: _remark
});

var postID = newPostRef.key();

var personRef = ref.child("person");
personRef.update({
    _person: postID
});
Run Code Online (Sandbox Code Playgroud)

但是,这会在子个人中创建一个名为_person的节点,而不是_person变量的值.使用set()会覆盖现有的人.

示例:首先使用子节点person/123456创建节点备注/ -JlkbxAKpQs50W7r84gf

之后我想创建一个节点人员/ 123456(仅当它不存在时),然后添加一个子节点remark/-JlkbxAKpQs50W7r84gf.自动生成post-id(Firebase),但是该人的id将从html表单中获取.

我怎么做?

javascript firebase

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

如何使用xml-resourcefile中的视图检索DialogFragment中的editText1

如何在此DialogFragment中检索editText1?它存在于vraag_banen.xml中,但getView()为null.

该对话框显示正常,也没有编译错误,但我无法弄清楚如何使用xml资源文件中的自定义视图为PositiveButton编写事件处理程序.

package mypackage;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

public class VraagBanenDialogFragment extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        // Get the layout inflater
        LayoutInflater inflater = getActivity().getLayoutInflater();

        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
        builder.setView(inflater.inflate(R.layout.vraag_banen, …
Run Code Online (Sandbox Code Playgroud)

android-dialogfragment

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

如何在Windows上使用Firebase-tools?

我想在Windows机器上开始使用firebase,但我不了解https://www.firebase.com/docs/web/quickstart.html上的入门说明.

我创建了一个包含以下内容的.html文件(从该页面上的说明复制).这样,信息被添加到数据库并从数据库中检索.但是我在Linux上丢失了像该页面上的$ npm install -g firebase-tools这样的指令.

我在https://www.firebase.com/docs/hosting/quickstart.html上的nodejs.org链接后面安装了nodejs

如果我在node.js屏幕上执行上面的命令(没有linux $ -prompt),我得到以下错误消息:npm应该在你的普通shell中运行在节点repl之外.(按Control-D退出.)

那么什么呢?

<html>
    <head>
        <script src="https://cdn.firebase.com/js/client/2.2.1/firebase.js"></script>
    </head>
    <body>
    <script>
        var myFirebaseRef = new Firebase("https://torrid-inferno-6000.firebaseio.com/");
        myFirebaseRef.set({
            title: "Hello!",
            author: "Firebase",
            location: {
                city: "San Francisco",
                state: "California",
                zip: 94103
            }
        });
        myFirebaseRef.child("location/city").on("value", function(snapshot) {
            alert(snapshot.val());  // Alerts "San Francisco"
        });
    </script>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

windows npm firebase firebase-tools

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

重置后无法选择以前选择的RadioButton

我有一组三个RadioGroup,每个组由三个RadioButtons组成.还有一个重置按钮,用于将所有组中的所有RadioButton设置为false(setChecked(false)).

重置工作正常(所有RadioButtons都未选中),但重置后,在每个RadioGroup中,只有那两个按钮可以被检查,在点击重置按钮的时刻没有检查.只有这样,才能像以前一样再次检查组中的所有三个按钮.

我试图在重置期间添加setFocusable(true)和setClickable(true),但这没有什么区别.那么焦点或可点击性还有什么可能导致这种情况以及如何解决?

我的目标是Android API 7.

这是完整的MainActivity.java:

    package nl.ch.simplescore;

import nl.ch.simplescore.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;

public class MainActivity extends Activity {

    Button scoretoevoegenButton; 
    RadioButton radio11RadioButton;
    RadioButton radio12RadioButton;
    RadioButton radio13RadioButton;
    RadioButton radio21RadioButton;
    RadioButton radio22RadioButton;
    RadioButton radio23RadioButton;
    RadioButton radio31RadioButton;
    RadioButton radio32RadioButton;
    RadioButton radio33RadioButton;

    TextView textView15;
    TextView textView16;
    TextView textView17;
    TextView textView18;
    TextView textView19;
    TextView textView20;
    TextView textView21;
    TextView textView22;
    TextView textView23;
    TextView textView24;
    TextView textView25;
    TextView textView26;


    int speler1score = 0;
    int …
Run Code Online (Sandbox Code Playgroud)

android unchecked radio-button

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

如何设置嵌套节点(Firebase,JavaScript)

我想存储一个嵌套节点

<html>
    <head>
        <script src="https://cdn.firebase.com/js/client/2.2.1/firebase.js"></script>
        <script language="javascript" type="text/javascript">
            var ref = new Firebase("https://mydatabase.firebaseio.com/");
            ref.child("clubs").set(
{
"03": { 
    "competities": 
        "102": { "aantalteams": 2 }
    } 
} );
        </script>   
    </head>
</html>
Run Code Online (Sandbox Code Playgroud)

这给了我一个'意外的令牌'错误,我添加了竞争ID"102".是否无法在Firebase中一次设置嵌套节点?或者怎么样?

javascript nested firebase

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