全局访问Spinner值

时间:2016-05-27 07:15:12

标签: android json

string.xml文件

$(document).ready(function(){//code});

mainactivity.java

<resources>
    <string name="app_name">MM</string>
    <string-array name="material_type">
        <item>Raw Material</item>
        <item>Finished Material</item>
        <item>Semi-finished Material</item>
    </string-array>
</resources>

即使我选择其他项目,也只有第一项&#34;原材料&#34;被存储到mysql数据库中。如何访问要存储到mysql数据库的选定值。

2 个答案:

答案 0 :(得分:0)

您使用Set Onclick侦听器,您需要使用以下界面进行任何项目点击或微调器值更改

{{1}}

答案 1 :(得分:0)

Spiner我们有setOnItemSelectedListener

        String temp [];
        Spinner s1=null;
        String materialType;

        temp = getResources().getStringArray(R.array.material_type);
            materialType = s1.getSelectedItem().toString();
            ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getApplicationContext(),
                    R.array.material_type, android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            s1.setAdapter(adapter);


            s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    materialType= temp[position];

                }

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

                }
            });