У меня есть специальный адаптер, который я хочу использовать для заполнения моего счетчика.Я использую модификацию и хочу получить ответ из файла JSon и передать его счетчику.Я пытался вызвать элементы списка на счетчик, но я застрял.Я новичок в Android и Java.Заранее спасибо
Call<RegistrationDropdownResponse> call = apiService.dropDownresponse(commonRequest);
call.enqueue(new Callback<RegistrationDropdownResponse>() {
@Override
public void onResponse(Call<RegistrationDropdownResponse> call, Response<RegistrationDropdownResponse> response) {
if (response.isSuccessful()) {
Log.e("RESPONSE", new Gson().toJson(response.body()));
Constants.registrationDropdownResponse = response.body();
CustomAdapter adapter = new CustomAdapter(this,);
spCompany.setAdapter(adapter);
}
}
@Override
public void onFailure(Call<RegistrationDropdownResponse> call, Throwable t) {
}
});
Вот мой класс ответа
public class RegistrationDropdownResponse {
private List<MaritalStatus> marital;
private List<IncomeBand> income;
private List<EducationLevel> education;
private List<Rental> rental;
private List<EmploymentLevel> employment;
public List<MaritalStatus> getMarital() {
return marital;
}
public List<IncomeBand> getIncome() {
return income;
}
public List<EducationLevel> getEducation() {
return education;
}
public List<Rental> getRental() {
return rental;
}
public List<EmploymentLevel> getEmployment() {
return employment;
}
}
CustomAdapter
public class CustomAdapter extends BaseAdapter implements SpinnerAdapter {
private ArrayList<SpinnerArrayObject> spinnerArrayObjects;
private Context context;
public CustomAdapter(Context context, ArrayList<SpinnerArrayObject> spinnerArrayObjects) {
this.spinnerArrayObjects = spinnerArrayObjects;
this.context = context;
}
@Override
public int getCount() {
return spinnerArrayObjects.size();
}
@Override
public SpinnerArrayObject getItem(int position) {
return spinnerArrayObjects.get(position);
}
@Override
public long getItemId(int position) {
return
spinnerArrayObjects.get(position).getId();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = View.inflate(context, R.layout.company_main, null);
TextView textView = (TextView) view.findViewById(R.id.main);
textView.setText((CharSequence) spinnerArrayObjects.get(position));
return textView;
}
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View view;
view = View.inflate(context, R.layout.company_dropdown, null);
final TextView textView = (TextView) view.findViewById(R.id.dropdown);
textView.setText(spinnerArrayObjects.size());
return view;
}
}
spinner arrayObject
public class SpinnerArrayObject {
private int id;
private String name;
public SpinnerArrayObject() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}