Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.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
Java 如何处理NumberPicker值更改?_Java_Android_Numberpicker - Fatal编程技术网

Java 如何处理NumberPicker值更改?

Java 如何处理NumberPicker值更改?,java,android,numberpicker,Java,Android,Numberpicker,我有一个NumberPicker,里面有游戏的标题。 问题是,我希望每次有人滚动NumberPicker并停在其中一个标题处时,我都能够立即处理此操作,并用我想要的信息填充2EditText 按下按钮时,有一个void onClick(视图视图)处理每次按下视图上的按钮时,如何使用NumberPicker执行类似操作 这是我的代码: NumberPicker picker; SharedPreferences sp; String JsonDataGL; String[] arrayGL; Pr

我有一个
NumberPicker
,里面有游戏的标题。 问题是,我希望每次有人滚动
NumberPicker
并停在其中一个标题处时,我都能够立即处理此操作,并用我想要的信息填充2
EditText

按下按钮时,有一个
void onClick(视图视图)
处理每次按下视图上的
按钮时,如何使用
NumberPicker
执行类似操作

这是我的代码:

NumberPicker picker;
SharedPreferences sp;
String JsonDataGL;
String[] arrayGL;
ProgressDialog p;
GamesLibrary[] gamesArray;
String Count = "0";
EditText gameTitleET, gameContentET;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_post);
    sp=getSharedPreferences("JsonData", 0);
    JsonDataGL = sp.getString("JsonGL", null);

    gameTitleET = findViewById(R.id.GameTitleET); //The 2 EditTexts I want to fill with text
    gameContentET = findViewById(R.id.GameTitleET);

    JSONObject json_data = null;
    try {
        json_data = new JSONObject(JsonDataGL);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    try {
        Count = json_data.getString("count");
        Log.d("Nugi32", Count);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    gamesArray = new GamesLibrary[Integer.parseInt(Count)];

    picker = (NumberPicker) findViewById(R.id.numberPicker2);
    picker.setMinValue(0);
    picker.setMaxValue(Integer.parseInt(Count)-1);
    arrayGL = new String[Integer.parseInt(Count)];
    DownLoadJsonGL downLoadJsonGL = new DownLoadJsonGL();
    downLoadJsonGL.execute(JsonDataGL); //Here The NumberPicker is filled with the titles

}
你知道我怎么做吗?还是带我去在线辅导? 因为我在网上找不到关于这个话题的任何关注点。
谢谢大家!

为此,您是否尝试了on value change侦听器?当数字选择器中的值更改时,将调用它。

如图所示, 你可以用

picker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal){
                //Process the changes here
            }
    });

你必须为此创建自己的数字签名器。你是什么意思?好吧,看来有办法找到@ZeekHugh answerHi谢谢你的帮助!这似乎正是我想要的,但我不知道如何通过此函数检查我当前的NumberPicker值是否已更改。它将为您提供旧值和新值,而且我认为只有在发生实际更改时才调用此方法也是一种检查。比如,如果你不间断地连续滚动,并且它达到了prevoius值,那么我认为它不会被调用。
picker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal){
                //Process the changes here
            }
    });