2016-03-02 80 views
0

这是我的需求,我需要从sqlite中设置字符串,并将其分配给微调真的很困惑如何做到这一点,当我点击编辑按钮在这里它将去下一个活动在这里我将检索所有值我已设置值edittext但不能设置值spinner我怎么能做到这一点到目前为止,我曾尝试是:如何将字符串值设置为从微软的微调?

RequestQueue queue_company_name = Volley.newRequestQueue(getBaseContext()); 
    final ArrayList<Model_Account> arrayobj_company_name = new ArrayList<Model_Account>(); 
    String Url_company_name = "http://xxx/xxx/xxx/AcoountCreatePageLoad.svc/Account/Accouxxxt"; 
    JsonObjectRequest jsonObjRequest_company_name = new JsonObjectRequest(Request.Method.GET, Url_company_name, new JSONObject(), 
      new Response.Listener<JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 
        String server_response = response.toString(); 
        try { 
         JSONObject json_object = new JSONObject(server_response); 
         JSONArray json_array = new JSONArray(json_object.getString("AccountPageLoadAccountListResult")); 
         for (int i = 0; i < json_array.length(); i++) { 
          Model_Account model_spinner = new Model_Account(); 
          JSONObject json_arrayJSONObject = json_array.getJSONObject(i); 
          model_spinner.setName(json_arrayJSONObject.getString("CompanyName")); 
          model_spinner.setCompanyname(json_arrayJSONObject.getInt("AccountID")); 
          arrayobj_company_name.add(model_spinner); 

         } 


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

       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_SHORT).show(); 

       } 
      }); 

    //Creating request queue 

    queue_company_name.add(jsonObjRequest_company_name); 

    ArrayAdapter<Model_Account> company_names = new ArrayAdapter<Model_Account>(this, android.R.layout.simple_spinner_dropdown_item, arrayobj_company_name); 
    spinner_company_name.setAdapter(company_names); 
final Bundle extra = getIntent().getExtras(); 
if (extra != null) { 

    id = extra.getInt("id"); 

    Cursor edit_accnt = account_sf_db.getData(id); 
    if (edit_accnt.moveToFirst()) { 
     do { 


      compny_group.setText(edit_accnt.getString(edit_accnt.getColumnIndex(Model_Account.company_groups))); 
      company_name.setText(edit_accnt.getString(edit_accnt.getColumnIndex(Model_Account.Parent_company))); 
      addrss1.setText(edit_accnt.getString(edit_accnt.getColumnIndex(Model_Account.Address_line1))); 
      address_2.setText(edit_accnt.getString(edit_accnt.getColumnIndex(Model_Account.Address_line2))); 
      address_3.setText(edit_accnt.getString(edit_accnt.getColumnIndex(Model_Account.Address_line3))); 
      pin_code.setText(edit_accnt.getString(edit_accnt.getColumnIndex(Model_Account.Pincode))); 
      land_line.setText(edit_accnt.getString(edit_accnt.getColumnIndex(Model_Account.Landline1))); 
      landline_2.setText(edit_accnt.getString(edit_accnt.getColumnIndex(Model_Account.Landline2))); 
      url.setText(edit_accnt.getString(edit_accnt.getColumnIndex(Model_Account.Url))); 
      email.setText(edit_accnt.getString(edit_accnt.getColumnIndex(Model_Account.Landline2))); 
      String match = edit_accnt.getString(edit_accnt.getColumnIndexOrThrow(Model_Account.Company_name)); 
      Log.e("test",match); 
     } while (edit_accnt.moveToNext()); 



    } 
} 

如何设置匹配适配器公司名称与此挣扎可以someonehelp我!

回答

0

首先得到你想要设置使用适配器

int position = spinnerAdapter.getPosition(json_arrayJSONObject.getString("CompanyName")); 

后,要微调器中的字符串中的位置,与位置选择在旋转

spinner.setSelection(position); 

希望这对你的作品。

+0

我这样做没有什么工作 – Yog

+0

这将是因为你想要设置的字符串的位置将返回-1指示微调没有该项目 –

+0

你得到-1 – Yog