获取微调器值并使用齐射发布到数据库

时间:2018-01-31 16:00:00

标签: android android-studio android-volley android-spinner

我要将POST微调器的值传递给数据库  遗憾的是,我不知道如何在CODE的任何部分实现POST方法。 我在发送Snipper值方面遇到了问题。

   public class FormActivity extends AppCompatActivity implements 

   ....


 spinnerStudy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
        String all_study =  spinnerStudy.getItemAtPosition(spinnerStudy.getSelectedItemPosition()).toString();
        if(!Objects.equals(all_study, "")){
            Toast.makeText(getApplicationContext(),all_study, Toast.LENGTH_SHORT).show();
        }
    }
    @Override
    public void onNothingSelected(AdapterView<?> adapterView) {
        // DO Nothing here
    }
    });
    spinnerCity.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String all_city =  spinnerCity.getItemAtPosition(spinnerCity.getSelectedItemPosition()).toString();

            if(!Objects.equals(all_city, "")) {
                Toast.makeText(getApplicationContext(), all_city, Toast.LENGTH_SHORT).show();
            }
        }
        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            // DO Nothing here
        }
    });
        s

    pinnerUniversity.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                String all_university =  spinnerUniversity.getItemAtPosition(spinnerUniversity.getSelectedItemPosition()).toString();
                if(!Objects.equals(all_university, "")) {
                    Toast.makeText(getApplicationContext(), all_university, Toast.LENGTH_SHORT).show();
                }
            }
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                // DO Nothing here
            }
        });

        spinnerUnited.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

                String all_united =  spinnerUnited.getItemAtPosition(spinnerUnited.getSelectedItemPosition()).toString();
                if(!Objects.equals(all_united, "")) {
                    Toast.makeText(getApplicationContext(), all_united, Toast.LENGTH_SHORT).show();

                }
            }
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                // DO Nothing here
            }
        });

        button.setOnClickListener(this);
...

请帮助我......在这个案例中,post方法如何发送参数? 如何从Spinner获得一个公共字符串?谢谢大家

1 个答案:

答案 0 :(得分:2)

    mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    //position is spinner position

                    //mySpinner.getSelectedItem().toString(); IS value of position (string)


                    mMap.put("your Key",mySpinner.getSelectedItem().toString());
//the value add to map of volley
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });