0

JSON 応答から「client_id」と「organization」のリストを取得し、これらの組織リストを spinner に渡す必要がありますが、ユーザーがスピナーから組織名を選択すると、その組織に関連付けられた client_id をサーバーに渡す必要があります。

これが私のコードです。

   try {

      //*** Getting Array of Attributes
            attributes = jsonreturn.getJSONObject(TAG_ATTRIBUTE);
            String status = attributes.getString(TAG_VALIDCODE);
            JSONObject clients = jsonreturn.getJSONObject(TAG_CLIENTS);
            JSONArray client = clients.getJSONArray(TAG_CLIENT);

            final String[] list_client_id = new String[client.length()+1];
            list_client_id[0]= "Select Client";
            final String[] list_client_name = new String[client.length()];

       if(status.equals("200")){

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

         {
            JSONObject clientlist = client.getJSONObject(i);

     //***** Storing each JSON item in variable
             String client_id = clientlist.getString(TAG_CLIENT_ID);
             String organization = clientlist.getString(TAG_ORGANIZATION);



          list_client_id[i+1]= clientlist.getString(TAG_CLIENT_ID);
          list_client_name[i]= clientlist.getString(TAG_ORGANIZATION);
         }
       }

       else{
            Toast.makeText(this, "Invalid Details", 1000).show();       }

        ClientNameSpinner = (Spinner)findViewById(R.id.ClientId);



        ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.simple_spinner_item, list_client_name);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        ClientNameSpinner.setAdapter(adapter);

       /* ArrayAdapter<String> adapterid = new ArrayAdapter<String> (this, android.R.layout.simple_spinner_item, list_client_id);
        adapterid.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        ClientNameSpinner.setAdapter(adapterid);*/

}
            catch (JSONException e)
            {
            e.printStackTrace();
            } 
4

1 に答える 1

0
ClientNameSpinner .setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
        // 
    }

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

    }

});
于 2012-05-08T08:11:15.703 に答える