更改RecycleView项的状态

时间:2018-04-30 15:59:16

标签: java android android-recyclerview

我有一个请求标签,其中“RECEIVED”在RecycleView中从BD Firebase检索数据。该请求由用户提出并由公司接收。现在我该怎么做:

1 - 公司代表点击传入请求的项目以显示AlertDialog是否响应请求。

2 - 如果你回答,删除“RECEIVED”项并出现在“ATTENDED”中。如果没有,请出现在“PENDING”中。

如果可能,还会通知用户这些操作。感谢无论谁帮忙。

代码:

    public class SolicRecebidaFragment extends Fragment {

private RecyclerView recyclerViewListaSolicitacao;
private DatabaseReference refSolicitacao, database ;
private AdapterSolicitacoes adapter;
private ArrayList<DadosSolicitacao> listaSolicitacoes = new ArrayList<>();
private ValueEventListener valueEventoSolicitacao;
private String idUsuario;


public SolicRecebidaFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view =  inflater.inflate(R.layout.fragment_solicitacao_recebida, container, false);

    //Config.Inciais
    recyclerViewListaSolicitacao = view.findViewById(R.id.recyclerView_ListaSolicitacao);

    //Config.Referenciar nó de recuperação dos dados
   // idUsuario = IdUsuarioFirabase.getIdentificadorUsuario();
    database = ConfiguracaoFirebase.getFirebaseDataBase();
    refSolicitacao = database
            .child("solicitacao_coleta");

    //Config.Adapter
    adapter = new AdapterSolicitacoes(listaSolicitacoes, getActivity());

    //Config.RecyclerView
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recyclerViewListaSolicitacao.setLayoutManager( layoutManager);
    recyclerViewListaSolicitacao.setHasFixedSize(true);
    recyclerViewListaSolicitacao.addItemDecoration( new DividerItemDecoration(getActivity(), LinearLayout.VERTICAL));
    recyclerViewListaSolicitacao.setAdapter( adapter );

    //Evento de click
    recyclerViewListaSolicitacao.addOnItemTouchListener(
            new RecyclerItemClickListener(getActivity(), recyclerViewListaSolicitacao,
                    new RecyclerItemClickListener.OnItemClickListener() {
                        @Override
                        public void onItemClick(View view, int position) {

                            Toast.makeText(getActivity(), "Item clicado",
                                    Toast.LENGTH_SHORT).show();
                        }

                        @Override
                        public void onLongItemClick(View view, int position) {

                            Toast.makeText(getActivity(), "Item pressionado",
                                    Toast.LENGTH_SHORT).show();

                        }

                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                        }
                    })
    );

return view;
}

@Override //Exibi lista ao carregar o fragment
public void onStart() {
    super.onStart();
    recuperarSolicitacao();
}

@Override // Remove lista ao sair do fragment
public void onStop() {
    super.onStop();
    refSolicitacao.removeEventListener(valueEventoSolicitacao);
}

public void recuperarSolicitacao (){

   valueEventoSolicitacao =  refSolicitacao.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            listaSolicitacoes.clear();

            for ( DataSnapshot dados: dataSnapshot.getChildren() ){

               // Log.i("DADOS COLETA FIREBASE", dataSnapshot.getValue().toString());

                DadosSolicitacao solicitacao = dados.getValue(DadosSolicitacao.class);
                listaSolicitacoes.add( solicitacao );

            }

            adapter.notifyDataSetChanged();

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });


}

    }

0 个答案:

没有答案