我正在编写一个代码,其中spinner由来自webservice的数据填充。我正在使用改造
RestAdapter adapter = new RestAdapter.Builder().setEndpoint(InterfaceApi.URL).build();
InterfaceApi interfaceApi = adapter.create(InterfaceApi.class);
interfaceApi.getAdminLeaveTypes(new Callback<ArrayList<AdminLeaveTypeBeans>>() {
@Override
public void success(ArrayList<AdminLeaveTypeBeans> adminLeaveTypeBeanses, Response response) {
if (adminLeaveTypeBeanses.isEmpty()) {
Toast.makeText(getActivity(), "No record found", Toast.LENGTH_SHORT).show();
} else {
for (int i = 0; i < adminLeaveTypeBeanses.size(); i++) {
leaveTypeId.add(i, adminLeaveTypeBeanses.get(i).getTypeId());
leaveTypeName.add(i, adminLeaveTypeBeanses.get(i).getTypeName());
}
}
}
@Override
public void failure(RetrofitError error) {
Toast.makeText(getActivity(), "Error..may be webservice not running", Toast.LENGTH_SHORT).show();
Log.e("failure: ", "messgae" +error.getMessage());
}
});
ArrayAdapter<String> adapterLeaveType = new ArrayAdapter<>(this.getContext(), android.R.layout.simple_list_item_1, leaveTypeName);
spinnerLeaveAdminType.setAdapter(adapterLeaveType);
我希望在选择spinner之后设置值。任何帮助将不胜感激。感谢
答案 0 :(得分:0)
只需在setAdapter(..)
之前添加此行: -
spinnerLeaveAdminType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
答案 1 :(得分:0)
将项目添加到列表
后,您需要通知适配器数据更改adapterLeaveType.notifyDataSetChanged();
答案 2 :(得分:0)
ArrayAdapter<String> adapterLeaveType = new ArrayAdapter<>(this.getContext(), android.R.layout.simple_list_item_1, leaveTypeName);
spinnerLeaveAdminType.setAdapter(adapterLeaveType);
将其更改为:
ArrayAdapter<String> adapterLeaveType = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, leaveTypeName);
adapterLeaveType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerLeaveAdminType.setAdapter(adapterLeaveType);