无法将地图显示为微调器

时间:2018-02-19 16:02:38

标签: android dictionary spinner

在这里,我从我的服务器接收一张地图,就像这样 { “字符串”= 1时, “String2的”= 4,STRING5 = 5} 当我尝试在微调器中显示它时,它将无法工作。我希望我的微调器显示String,String2,String5

这是我更新的代码。运行此操作时,我的微调器不会显示任何显示为空白的内容。我尝试了很多不同的微调器配置。

public class NewScan extends AppCompatActivity implements View.OnClickListener,AdapterView.OnItemSelectedListener{




    private static final int PICK_FILE_REQUEST = 1;
    private static final String TAG = NewScan.class.getSimpleName();
    private String selectedFilePath;
    private String SERVER_URL = "http:xx/permissionstest/";
    private String PROJECTS_URL = "http:x//getprojects/";
    //Image View
    ImageView ivAttachment;
    //Upload button
    Button bUpload;
    Button Save;
    TextView tvFileName;
    ProgressDialog dialog;
    TextView Rv;
    TextView Gv;
    TextView Bv;
    String Ri;
    String Gi;
    String Bi;
    String description;

    Spinner spin;
    Map m;
    List<String> keylist = new ArrayList<String>();



@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_scan);
        ivAttachment = (ImageView) findViewById(R.id.galleryImgView);
        Save = (Button) findViewById(R.id.opengallery);
        bUpload = (Button) findViewById(R.id.saveimage);

        ivAttachment.setOnClickListener(this);
        bUpload.setOnClickListener(this);
        EditText desc = (EditText) findViewById(R.id.description);
        description = desc.getText().toString();
        m = new HashMap<String, String>();
        Rv = (TextView) findViewById(R.id.Rvalue);
        Gv = (TextView) findViewById(R.id.Gvalue);
        Bv = (TextView) findViewById(R.id.Bvalue);
        //Get the descroption and name of the new project.
        getProjects();
        System.out.println(Arrays.toString(keylist.toArray()));

        String[] projectnames = keylist.toArray(new String[0]);

        spin = (Spinner) findViewById(R.id.spinnerid);
        ArrayAdapter adapt = new ArrayAdapter(NewScan.this,android.R.layout.simple_spinner_item, projectnames);
        adapt.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spin.setAdapter(adapt);
    }

public void getProjects() {
    String url = PROJECTS_URL;
    System.out.println("getProjects");
    StringRequest postRequest = new StringRequest(Request.Method.POST, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        System.out.println(response);
                        JSONObject object = new JSONObject(response);
                        Iterator keys = object.keys();
                        ;
                        //This gets all the keys in a list for later on.
                        while(keys.hasNext()){
                            String key = (String) keys.next();
                            //projectnames[i]=key;
                            keylist.add(key);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                }
            }
    ) {
        @Override
        protected Map<String, String> getParams()
        {
            SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(NewScan.this);
            String tkn = pref.getString("token",null);
            Map<String, String>  params = new HashMap<>();
            // the POST parameters:
            params.put("usertoken", tkn);

            return params;
        }
    };
    Volley.newRequestQueue(this).add(postRequest);
}

0 个答案:

没有答案