使用数据库值填充微调器时出错

时间:2017-03-15 16:05:50

标签: java android

这是我的代码:

声明设置内容视图:

GetDataAdapter1 = new ArrayList<>();

        // spinner item select listener
        spinnerCountry.setOnItemSelectedListener(this);

这是我正在使用Json请求的解析值。

public void JSON_PARSE_DATA_AFTER_WEBCALL(JSONArray array) {

    for (int i = 0; i < array.length(); i++) {

        Country GetDataAdapter2 = new Country();

        JSONObject json = null;
        try {

            json = array.getJSONObject(i);

            GetDataAdapter2.setName(json.getString("country_name"));
           GetDataAdapter2.setId(json.getString("id"));


        } catch (JSONException e) {

            e.printStackTrace();
        }
        GetDataAdapter1.add(GetDataAdapter2);
    }


    //Setting adapter to show the items in the spinner
    spinnerCountry.setAdapter(new ArrayAdapter<String>(DataComplet.this, android.R.layout.simple_spinner_dropdown_item, GetDataAdapter1));

}

这是我得到的错误:

Cannot resolve constructor 'ArrayAdapter(com.futegolo.jobnow.DataComplet, int, java.util.List<com.futegolo.jobnow.Configs.Country>)'

1 个答案:

答案 0 :(得分:0)

您正在使用自定义模型对象Country来加载微调器,这不起作用:

 spinnerCountry.setAdapter(new ArrayAdapter<String>(DataComplet.this, android.R.layout.simple_spinner_dropdown_item, GetDataAdapter1));

试试这个:

  ArrayAdapter<Country> adapter =
                new ArrayAdapter<Country>(getApplicationContext(), R.layout.simple_spinner_dropdown_item, GetDataAdapter1);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);

spinnerCountry.setAdapter(adapter);