我有2个微调器,每个都包含文本视图和ProgressBar。 当我在第二个sprinner中选择元素时,应该看到ProgressBar和服务器的请求应该获取一些数据并填充一个微调器,在填充微调器之后,progressBar应该是不可分割的。 现在,在第二个微调器上从第一个微调器中选择一个元素后,将显示ProgressBar(发出请求),只有当从第二个微调器中选择了项目时才会隐藏ProgressBar。 我不知道我应该在代码中更改什么,请帮忙。 这是我的代码:
微调:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = mInflater.inflate(...);
TextView itemView = (TextView) row.findViewById(...);
mProgressBar = (ProgressBar) row.findViewById(...);
//mProgressBar.setVisibility(View.INVISIBLE);
T item = getItem(position);
String itemLabel = null;
itemLabel = mContext.getString(R.string.dialog_filters_item, item.getName());
}
itemView.setText(itemLabel);
return row;
}
@Override
public void setProgressBarVisibility(final boolean visibility) {
if (mProgressBar != null) {
if (visibility) {
mProgressBar.setVisibility(View.VISIBLE);
} else {
mProgressBar.setVisibility(View.INVISIBLE);
}
Log.v(TAG, "changed visibility on spinner " + visibility);
}
}
带有微调器的碎片:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
.... //spinner1 && spniner2 methods run on UI Threads
spinner1SetProgressBarVisibility(true);
spinner2SetProgressBarVisibility(false); //request to server
mHost.populateSpinner1(); ....
return v;
}
private void populateSpinner1Spinner(List<Data> dataServerItems) {
Data dataAll = new Data();
dataAll.setDepName(...);
dataAll.setDepNumber(...);
mDataItems.clear();
mDataItems.add(dataAll);
if (dataServerItems != null) {
mDataItems.addAll(dataServerItems);
}
spinner1SetProgressBarVisibility(false);
spinner2SetProgressBarVisibility(false);
mSpinner1DataAdapter.notifyDataSetChanged();
}
private void populateSectionsSpinner(List<Data2> dataServerItems) {
Data2 dataAll = new Data2();
dataAll.setSectionName(getString(...));
dataAll.setSectionNumber(...);
mData2Items.clear();
mData2Items.add(0, dataAll);
if (dataServerItems != null) {
mSectionItems.addAll(dataServerItems);
spinner1SetProgressBarVisibility(false);
spinner2SetProgressBarVisibility(false);
mSpinner2DataAdapter.notifyDataSetChanged();
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Log.v(TAG, "onItemSelected, position=" + position);
switch (parent.getId()) {
case R.id.spinner1:
spinner1SetProgressBarVisibility(false);
mHost.getData2();
spinner2SetProgressBarVisibility(true);
break;
case R.id.spinner2:
...
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// Not used
}
@Override
public void onDataUpdate(List<Data> dataServerItems) {
populateSpinner1Spinner(List<Data> dataServerItems);
}
@Override
public void onData2Update(List<Data2> dataServerItems) {
populateSpinner2Spinner(List<Data> dataServerItems);
} private void spinner1SetProgressBarVisibility(final boolean isVisible) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mSpinner1DataAdapter.setProgressBarVisibility(isVisible);
}
});
}
private void spinner2SetProgressBarVisibility(final boolean isVisible) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mSpinner2DataAdapter.setProgressBarVisibility(isVisible);
}
});
} }
答案 0 :(得分:0)
问题是由CustomAdapter引起的。在进度条的默认可见性设置为false