Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从sqlite将字符串值设置为微调器?_Android_Sqlite_Spinner - Fatal编程技术网

Android 如何从sqlite将字符串值设置为微调器?

Android 如何从sqlite将字符串值设置为微调器?,android,sqlite,spinner,Android,Sqlite,Spinner,这是我的要求我需要从sqlite设置字符串并将其分配给spinner我真的很困惑如何做当我单击编辑按钮这里它将转到下一个活动这里我将检索所有值我已将值设置为edittext但无法将值设置为spinner到目前为止我尝试的是: RequestQueue queue_company_name = Volley.newRequestQueue(getBaseContext()); final ArrayList<Model_Account> arrayobj_company

这是我的要求我需要从sqlite设置字符串并将其分配给spinner我真的很困惑如何做当我单击编辑按钮这里它将转到下一个活动这里我将检索所有值我已将值设置为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());



    }
}
RequestQueue\u company\u name=Volley.newRequestQueue(getBaseContext());
最终ArrayList arrayobj_公司名称=新ArrayList();
字符串Url\公司\名称=”http://xxx/xxx/xxx/AcoountCreatePageLoad.svc/Account/Accouxxxt";
JsonObjectRequest JsonObjectRequest_company_name=新JsonObjectRequest(Request.Method.GET,Url_company_name,new JSONObject(),
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
字符串服务器_response=response.toString();
试一试{
JSONObject json_object=新的JSONObject(服务器_响应);
JSONArray json_数组=新的JSONArray(json_object.getString(“AccountPageLoadAccountListResult”);
for(int i=0;i

如何设置适配器公司名称的匹配,有人能帮我吗

首先,使用适配器获取要设置为微调器的字符串的位置

int position = spinnerAdapter.getPosition(json_arrayJSONObject.getString("CompanyName"));
之后,选择“带位置的微调器”

spinner.setSelection(position);

希望这对您有用。

这是因为您要设置的字符串的位置将返回-1,表示spinner没有该项是的,这是我在上面的评论中告诉您的。如果微调器没有该项,您将得到它的位置为-1。那么如何纠正它,首先您必须为微调器设置所有数据值。一旦你们调用了API,那个么在你们的API的响应中,你们就可以使用SpinNerAdapter从spinner中获取数据字符串的位置,然后如何做到这一点,因为我正在努力解决这个问题