想要启动微调器添加类别但显示微调器的第一个类别文本

时间:2016-06-10 06:17:01

标签: android listview android-volley android-spinner

我的应用程序包含带有微调器的listview,当选择微调器类别后,该值除以类别但是当微调器注意选择时,然后在列表视图中显示所有值 但是我的微调器包含来自微调器的第一项的值

 private void getData() {
    StringRequest stringRequest = new StringRequest(Config.DATA_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    JSONObject j_obj = null;
                    try {
                        j_obj = new JSONObject(response);
                        result = j_obj.getJSONArray(Config.JSON_ARRAY);
                        //Calling method getStudents to get the students from the JSON Array
                        getStudents(result);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                }
            });
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}
private void getStudents(JSONArray j) {
    for (int i = 0; i < j.length(); i++) {
        try {
            JSONObject json = j.getJSONObject(i);
            students.add(json.getString(Config.TAG_USERNAME));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    //Setting adapter to show the items in the spinner
    spinner.setAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, students));
}
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    String text_spinner = spinner.getSelectedItem().toString();
    j_data.setSpintext(text_spinner);
    makeJsonArrayRequest();
    Toast.makeText(MainActivity.this, "Get Value from spinner"    +text_spinner, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}

enter image description here

帮帮我

1 个答案:

答案 0 :(得分:0)

您可以做的一个简单技巧是在&#34;学生&#34;的第0(第0)索引处添加类别名称。收集,然后在Spinner的onItemSelected列表器中忽略该位置的功能为0(零)。