Android Spinner不起作用

时间:2018-07-11 11:57:14

标签: java android xml android-spinner android-custom-view

我正在做一个从API检索其项目的微调器,我检查了邮递员的结果,但是那里没有错误,而且我什至不能单击微调器,或者微调器只是没有下拉,这是代码,我检查了所有其他解决方案已经存在,但不是很像这样

Spinner xml:

<Spinner
        android:id="@+id/select_plan_spinner"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="10dp"
        android:layout_weight="1"
        android:background="@drawable/sos_edit_bg"
        android:gravity="center"
        android:spinnerMode="dropdown"
        android:textColor="@color/white_new"
        android:visibility="visible"></Spinner>

微调框:

plan_spinner = (Spinner) findViewById(R.id.select_plan_spinner);

plan_spinner:

plan_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            plan_id = PLAN_ID.get(position);
            Double price = PLAN_PRICE.get(position);

            planprice = price;
            Log.e("planprice", "planprice>>" + planprice);

            if (plan_id != 0) {
                int pos = position - 1;

                String view_route = feeditem.get(pos).getIMEI();

                if (view_route.equals("0")) {

                    view_route = "No";
                } else {
                    view_route = "yes";
                }

                desc.setText("Description: " +
                        feeditem.get(pos).getMessage() + "\n View Route History: " + view_route);

            } else {

                desc.setText("Please select plan");
            }
        }

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

        }

API:

private void Get_plan_list() {
    // TODO Auto-generated method stub
    pDialog = new ProgressDialog(Select_plan.this);
    pDialog.setMessage("Please wait...");
    pDialog.setCancelable(false);
    pDialog.show();
    StringRequest req = new StringRequest(Request.Method.POST, Config.YOUR_API_URL + "planlist",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    pDialog.dismiss();
                    // response
                    Log.e("Responsesearch", response);
                    try {
                        JSONObject obj = new JSONObject(response);
                        int success = obj.getInt("success");
                        if (success == 1) {
                            JSONArray array = obj.getJSONArray("planlist");
                            for (int i = 0; i < array.length(); i++) {
                                JSONObject jsobj = array.getJSONObject(i);

                                int p_id = jsobj.getInt("plan_id");
                                plan_name = jsobj.getString("plan_name");
                                planprice = jsobj.getDouble("plan_price");
                                timeperoide = jsobj.getString("view_route");
                                allow_devices = jsobj.getString("allowed_device");
                                description = jsobj.getString("description");

                                UserData detail = new UserData();

                                detail.setID(p_id);
                                detail.setName(plan_name);
                                detail.setEmail(allow_devices);
                                detail.setMessage(description);
                                detail.setIMEI(timeperoide);
                                detail.setMobile(String.valueOf(planprice));

                                feeditem.add(detail);

                                PLAN_ID.add(p_id);
                                PLAN_PRICE.add(planprice);
                                PLAN_NAME.add(plan_name + "( USD " + planprice + ")");

                                ArrayAdapter<String> data2 = new ArrayAdapter<String>(Select_plan.this,
                                        R.layout.spinner_item, PLAN_NAME);

                                plan_spinner.setAdapter(data2);

                                // for auto set spinner Value

                                Log.e("plan_id_intent", "plan_id_intent>>" + plan_id_intent);


                                if (plan_id_intent == null) {

                                } else {
                                    int position = Integer.parseInt(plan_id_intent);
                                    int index = PLAN_ID.indexOf(position);
                                    plan_spinner.setSelection(index);
                                }


                            }

                        } else if (success == 0) {
                            String msg = obj.getString("text");
                            Toast.makeText(getApplicationContext(), "" + msg, Toast.LENGTH_LONG).show();
                        } else if (success == 2) {

                        }

                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        Log.e("Error.Response", e.toString());
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    pDialog.dismiss();

                    // error
                    Log.e("Error.Response", error.toString());
                }
            }
    ) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            return params;
        }
    };

    // for response time increase
    req.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    req.setShouldCache(false);
    AppController.getInstance().addToRequestQueue(req);

}

0 个答案:

没有答案