我有一个带有微调器和listView的活动。根据在微调器上选择的项目,列表视图显示不同的数据。 当我刷新im调用方法填充时,再次填充活动。问题是,微调器会假设我点击之前选择的相同项目,因此刷新后不会输入onSelectListener
public void populate(int idEnfermaria){
final String idS = String.valueOf(idEnfermaria);
spinnerNursery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(final AdapterView<?> adapterView, View view, final int position, long id) {
Toast.makeText(NurseryActivity.this, "Carregando...", Toast.LENGTH_SHORT).show();
if (position == 0) {
tvInfo.setText("Lista de utentes da enfermaria " + idS);
NetworkManager.getInstance().getUtentesEnfermaria(idS, new NetworkManager.ListaUtentesListener() {
@Override
public void recieveResponse(final List<Utente> listaUtentes, Exception erro) {
swipeRefreshNursery.setRefreshing(false);
if (listaUtentes != null) {
UtenteAdapter adapterUtentes = new UtenteAdapter(NurseryActivity.this, listaUtentes);
listViewUtentesOrProcs.setAdapter(adapterUtentes);
listViewUtentesOrProcs.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Utente utente = listaUtentes.get(position);
Intent intent = new Intent(NurseryActivity.this, PatientActivity.class);
intent.putExtra(Controlador.VIEW_PATIENT, utente);
startActivity(intent);
}
});
} else {
Toast.makeText(NurseryActivity.this, "Erro inesperado", Toast.LENGTH_SHORT).show();
System.out.println("ERRO: " + erro.toString());
}
}//fim do recieve response
});//final do listener de utentes
}
else if(position == 1){
tvInfo.setText("Lista de procedimentos da enfermaria " + idS);
NetworkManager.getInstance().getProcedimentosPorEnfermaria(idS, new NetworkManager.ListaProcedimentosListener() {
@Override
public void recieveResponse(final List<Procedimento> listaProcedimentos, Exception erro) {
swipeRefreshNursery.setRefreshing(false);
if (listaProcedimentos != null) {
final List<Procedimento> lista = Controlador.ordenarKardexUtente(listaProcedimentos);
ProcedimentoAdapter adapterProcs = new ProcedimentoAdapter(NurseryActivity.this, lista);
listViewUtentesOrProcs.setAdapter(adapterProcs);
listViewUtentesOrProcs.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Procedimento procedimento = lista.get(position);
Intent intent = new Intent(NurseryActivity.this, ProcedureActivity.class);
intent.putExtra(Controlador.VIEW_PROC, procedimento);
intent.putExtra(Controlador.ACTIVITY, Controlador.ACTIVITY_NURSERY);
startActivity(intent);
}
});
} else {
Toast.makeText(NurseryActivity.this, "Erro inesperado", Toast.LENGTH_SHORT).show();
System.out.println("ERRO: " + erro.getMessage());
}
}//fim do recieve response
});//final do listener de servicos
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});//fim do listener do spinnerNursery
listViewUtentesOrProcs.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int i1, int i2) {
if (firstVisibleItem == 0) {
swipeRefreshNursery.setEnabled(true);
} else swipeRefreshNursery.setEnabled(false);
}
});
}
我试图这样做,当我向下滑动,刷新活动时,它将进入填充并重新加载所有数据(输入onItemSelected等)。 我已尝试将spinner.setSelection(0)置于刷新状态,但只有在我之前选择的项目索引不同于0时才有效。 感谢