0
{
  "Platforms": [
    {
      "PlatformNo": "1",
      "SerialNumbers": [
        {
          "Aplilevel": "1",
          "Version": "1.0"
        },
        {
          "Aplilevel": "2",
          "Version": "1.1"
        },
        {
          "Aplilevel": "3",
          "Version": "1.5"
        },
        {
          "Aplilevel": "4",
          "Version": "1.6"
        }
      ]
    },
    {
      "PlatformNo": "2",
      "SerialNumbers": [
        {
          "Aplilevel": "5",
          "Version": "2.0"
        },
        {
          "Aplilevel": "6",
          "Version": "2.0.1"
        },
        {
          "Aplilevel": "7",
          "Version": "2.1.x"
        },
        {
          "Aplilevel": "8",
          "Version": "2.2.x"
        },
        {
          "Aplilevel": "9",
          "Version": "2.3"
        },
        {
          "Aplilevel": "10",
          "Version": "2.3.3"
        }
      ]
    },
    {
      "PlatformNo": "3",
      "SerialNumbers": [
        {
          "Aplilevel": "11",
          "Version": "3.0.x"
        },
        {
          "Aplilevel": "12",
          "Version": "3.1.x"
        },
        {
          "Aplilevel": "13",
          "Version": "3.2"
        }
      ]
    },
    {
      "PlatformNo": "4",
      "SerialNumbers": [
        {
          "Aplilevel": "14",
          "Version": "4.0"
        },
        {
          "Aplilevel": "15",
          "Version": "4.0.3"
        }
      ]
    }
  ]
}

上記の JSON は、PlatformNo のスピナーに表示する必要がある出力です。1 つの項目を選択すると、対応する API レベルを別のスピナーで取得する必要がありますか? 誰でもこれを解決するために私を助けてくれますか? 以下で取得しようとしていますが、正しく取得できません。次のスピナーでのみ最後の値を取得しています。これを確認する方法はありますか?私を助けてください。

String[] platfromno,apilevel;
Spinner splatform,sapilevel;  
JSONObject obj = json.getJSONObject("Result");
JSONArray platformObject = customerObject.getJSONArray("Platforms");
String parray = customerObject.getString("Platforms");
System.out.println("String of Platforms array is " + parray);

for (int i = 0; i < productNameObject.length(); i++) {
    JSONObject e = productNameObject.getJSONObject(i);
    platformno[i] = e.getString("PlatformNo");
    ArrayAdapter<String> spinnerPlatfromNo =
        new ArrayAdapter<String>( this,
                android.R.layout.simple_spinner_dropdown_item,
                platformno);

    splatform.setAdapter(spinnerPlatfromNo);
    JSONArray serialNumberObject = e.getJSONArray("SerialNumbers");
    apilevel= new String[serialNumberObject.length()];
    splatform.setOnItemSelectedListener(
        new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> arg0,
                            View arg1, int arg2, long arg3) {
                System.out.println("selected Item position is  " +
                    splatform.getSelectedItemPosition());
            }

            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
            }
    });

    // if (splatform.getSelectedItemPosition()) {

    for (int j = 0; j < serialNumberObject.length(); j++) {
        JSONObject e1 = serialNumberObject.getJSONObject(j);
        apilevel[j] = e1.getString("Aplilevel");
    // }
    }
4

1 に答える 1

0

たくさん試した後、ツイスターを解決しました。

String[] platfromno,apilevel;
Spinner splatform,sapilevel;


    JSONObject obj = json.getJSONObject("Result");
    JSONArray platformObject = customerObject
                        .getJSONArray("Platforms");

                for (int i = 0; i < platformObject.length(); i++) {

                    JSONObject e = platformObject.getJSONObject(i);

                    platformno[i] = e.getString("PlatformNo");


                    ArrayAdapter<String> spinnerPlatfromNo = new ArrayAdapter<String>(
                            this,
                            android.R.layout.simple_spinner_dropdown_item,
                            platformno);

                    splatform.setAdapter(spinnerPlatfromNo);

                    JSONArray serialNumberObject = e
                            .getJSONArray("SerialNumbers");

                    apilevel= new String[serialNumberObject.length()];


                    splatform.setOnItemSelectedListener(new OnItemSelectedListener() {

                        public void onItemSelected(AdapterView<?> arg0,
                                View arg1, int arg2, long arg3) {
                            System.out.println("selected Item position is  "
                                    + splatform.getSelectedItemPosition());

                fillApiLevel();

                        }

                        public void onNothingSelected(AdapterView<?> arg0) {
                            // TODO Auto-generated method stub

                        }
                    });


        public void fillApiLevel(){

                JSONArray serialNumberObject = null;
        try {
            serialNumberObject =platformObject .getJSONObject(
                    splatform.getSelectedItemPosition()).getJSONArray(
                    "SerialNumbers");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        platfromno = new String[serialNumberObject.length()];
        apilevel = new String[serialNumberObject.length()];

        for (int j = 0; j < serialNumberObject.length(); j++) {

            JSONObject e1 = null;
            try {
                e1 = serialNumberObject.getJSONObject(j);

                platfromno[j] = e1.getString("Aplilevel");
                apilevel [j] = e1.getString("Version");


            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            ArrayAdapter<String> spinnerSerialNumer = new ArrayAdapter<String>(
                    this, android.R.layout.simple_spinner_dropdown_item,
                    platformno);

            sSerialNo.setAdapter(spinnerSerialNumer);
                    }
于 2012-05-18T07:28:04.047 に答える