我的片段中有Spinner
但是当我点击微调器时,我没有得到实际的下拉列表来显示
这是我的Spinner
private void createCommissionDropDownList(){
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, mReportViewModel.getCommissionNames());
arrayAdapter.setDropDownViewResource(R.layout.spinner_my_spinner_item);
Spinner spinner = (Spinner) mBaseLayout.findViewById(R.id.commissionSpinner);
spinner.setVisibility(View.VISIBLE);
spinner.setAdapter(arrayAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int itemId = (int) id;
if(itemId == 0) {
Toast.makeText(getContext(), mReportViewModel.getCommissionNames().size() + "", Toast.LENGTH_LONG).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
这是Spinner
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:id="@+id/commissionSpinner"
android:visibility="gone"
android:background="@color/colorPrimary"/>
下图显示了它的外观
黄色是实际的微调器,但它不会响应我的点击次数
我调用我的方法在我的onCreateView
中创建微调器,如下所示。
我已经记录并制作了祝酒词,以确保它也被调用。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mBaseLayout = (PercentRelativeLayout) inflater.inflate(R.layout.fragment_report, container, false);
mShift = getActivity().getIntent().getParcelableExtra("shift");
if(mShift.getDate().isAfter(DateAndTime.getDateToday())) {
displayCantReportReason("Du kan inte tidsrapportera ett pass som är i framtiden");
} else {
if (mShift.isNewShift()) {
mReportViewModel = new ReportViewModel(null, null, new DataLoaderCallback() {
@Override
public void onDataLoaded() {
createForm();
}
});
} else {
mReportViewModel = new ReportViewModel(mShift.getCommissionId(), mShift.getDate(), new DataLoaderCallback() {
@Override
public void onDataLoaded() {
createForm();
}
});
}
}
return mBaseLayout;
}
public void createForm() {
if(mShift.isNewShift()){
createCommissionDropDownList();
}
else {
}
}