填充微调器 [自定义适配器] 改造

我有一个自定义适配器,我想用它来填充我的微调器。我正在使用改造,我想从 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;

}

}


红颜莎娜
浏览 66回答 1
1回答

湖上湖

好的,所以要实现这一点,您首先需要创建 xml 视图,例如:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; android:orientation="vertical">&nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/name_text_view"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content" /></LinearLayout>现在在函数中的适配器中,getView()您需要对其进行充气并绑定TextView:convertView = LayoutInflater.from(context).&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inflate(R.layout.layout_list_view_row_items, parent, false);TextView nameTextView = (TextView) convertView.findViewById(R.id.name_text_view);//and now get the SpinnerArrayObject by position&nbsp;SpinnerArrayObject currentObject = spinnerArrayObjects.get(position);&nbsp; &nbsp; nameTextView.setText(currentObject.getName());&nbsp; &nbsp; return convertView;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java