【发布时间】:2021-01-20 07:39:55
【问题描述】:
我正在尝试从服务器获取数据到可搜索微调器,但显示为空。我正在使用 改造和检查邮递员上的 api 它显示数据,但在 android studio 中显示 null。我只显示来自 mysql 数据库的国家名称,抱歉英语不好 感谢提前解决我的问题。
public class LabourRegActivity extends AppCompatActivity {
private ArrayList<String> countryname = new ArrayList<String>();
SearchableSpinner countryS,catagoryS,cityS,projectbaseS,district;
EditText name,contact,cnic,perdayrate,address;
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_labour_reg);
countryS = findViewById(R.id.country_spinner);
catagoryS = findViewById(R.id.skill_spinner);
cityS = findViewById(R.id.city_spinner);
projectbaseS = findViewById(R.id.projectBase);
district = findViewById(R.id.district_Spinner);
name = findViewById(R.id.Edt_name);
contact = findViewById(R.id.Edt_contact);
cnic = findViewById(R.id.Edt_cnic);
perdayrate = findViewById(R.id.Edt_perdays);
address = findViewById(R.id.Edt_address);
CountryFetchApi fetchApi = ApiClient.getClient().create(CountryFetchApi.class);
// HashMap<String, String> map = new HashMap<>();
Log.d("ok","countryMap"+fetchApi);
Call<List<CountryModel>> model = fetchApi.getcountryrecord();
model.enqueue(new Callback<List<CountryModel>>() {
@Override
public void onResponse(Call<List<CountryModel>> call, Response<List<CountryModel>> response) {
List<CountryModel> data = response.body();
Log.d("ok","country"+response.body());
for (int i = 0; i < data.size(); i++) {
countryname.add(data.get(i).getCountryName());
}
Log.d("leavename", countryS.toString());
adapter = new ArrayAdapter<String>(LabourRegActivity.this, R.layout.support_simple_spinner_dropdown_item,countryname);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
countryS.setAdapter(adapter);
}
@Override
public void onFailure(Call<List<CountryModel>> call, Throwable t) {
}
});
}
}
【问题讨论】:
-
您能否添加
CountryModel的代码和您收到的json 响应?可能是映射不正确
标签: java mysql xml retrofit2 android-studio-3.0