Android 我们可以使用适配器进行自定义视图吗?
我有AddressCustomView,我想在其中显示下拉列表中的状态列表。 我们可以使用适配器进行自定义视图吗?我想知道这条路对不对 以下是我正在尝试的: 自定义视图:Android 我们可以使用适配器进行自定义视图吗?,android,android-custom-view,Android,Android Custom View,我有AddressCustomView,我想在其中显示下拉列表中的状态列表。 我们可以使用适配器进行自定义视图吗?我想知道这条路对不对 以下是我正在尝试的: 自定义视图: public class AddressCustomView extends BaseCustomView { private StateListAdapter mStateListAdapter; public AddressCardView(@NonNull Context context, @NonNull Stat
public class AddressCustomView extends BaseCustomView {
private StateListAdapter mStateListAdapter;
public AddressCardView(@NonNull Context context, @NonNull StateListAdapter stateListAdapter) {
super(context);
this.mStateListAdapter = stateListAdapter.
}
适配器类:
public class StateListAdapter extends ArrayAdapter<State> {
private List<State> mStateList;
public StateListAdapter(@NonNull Context context, List<State> stateList) {
super(context);
this.mStateList = stateList;
}
}
公共类StateListAdapter扩展了ArrayAdapter{
私人名单;
公共StateListAdapter(@NonNull上下文,列表stateList){
超级(上下文);
this.mStateList=状态列表;
}
}
当然可以。但是适配器只为给定的索引生成一个单元格,因此您必须实现将单元格手动放置到视图中。还有,为什么不能使用ListView呢?谢谢@VladyslavMatviienko,实际上我必须使用已经实现的现有适配器。