Android在首选项屏幕上更改过滤器后刷新以前的活动

时间:2014-11-12 00:33:30

标签: java android android-activity callback onresume

当我按下后退按钮时,如何刷新我之前的活动,我有一个FilterActivity,当我按下后退按钮时,我想刷新它并仅显示已过滤的项目,到目前为止我尝试的内容没有成功:< / p>

MainActivity:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {



        // TODO Auto-generated method stub      
        rootView = inflater.inflate(R.layout.fragment_pedidos, container, false);


        rootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT ));


        rootView.setBackgroundColor(0xffdbe3cf);



        return rootView;
    }


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        setHasOptionsMenu(true);                                        
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // TODO Auto-generated method stub
        super.onCreateOptionsMenu(menu, inflater);      
        inflater.inflate(R.menu.menu, menu);

        SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(Menus.PROCURAR));
        searchView.setQueryHint(this.getString(R.string.search));

        ((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text))
        .setHintTextColor(getResources().getColor(R.color.white));      
        searchView.setOnQueryTextListener(OnQuerySearchView);





        try {

            pedidos = new ArrayList<PedidoModel>();
            lv = (ListView) rootView.findViewById(R.id.listaPedidos);

            ad = new PedidoViewAdapter(getActivity(),this, pedidos);

            lv.setVerticalFadingEdgeEnabled(true);
            lv.setVerticalScrollBarEnabled(true);
            lv.addFooterView(footerLinearLayout);
            lv.setOnScrollListener(new EndlessScrollListener(){
                @Override
                public void onLoadMore(int page, int totalItemsCount) {
                    new LoadMorePedidoTask(progressBar,FragmentPedidos.this,ad,getActivity()).execute(page);
                }
            });


            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    TextView clienteId = (TextView) view.findViewById(R.id.pedidoID);


                    Intent intent = new Intent(getActivity(), PedidoDetalheActivity.class);
                    intent.putExtra("id_pedido", clienteId.getText()); // envia o id do pedido para a tela de detalhes



                    startActivity(intent);
                    getActivity().overridePendingTransition(R.anim.animation_enter, R.anim.animation_leave);

                }


            });

            lv.setAdapter(ad);
            lv.removeFooterView(footerLinearLayout);
            new LoadMorePedidoTask(progressBar,this,ad,getActivity()).execute(0);

        } catch (Exception e) {
            e.printStackTrace();
        }


        menu.findItem(Menus.PROCURAR).setVisible(true);



        searchCheck = false;    
    }

    @Override
    public void onResume() {

        super.onResume();
        this.onCreate(null);
    }
}

FilterActivity:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        mSessao = new SecurePreferences(getApplicationContext(), "sessao");


        menuAtual = (mSessao.getString("menuAtual") != null) ? mSessao.getString("menuAtual") : "Pedidos";

        setTitle("Filtrar " + menuAtual);

        if (menuAtual.equals("Viagens")) {

        } else if (menuAtual.equals("Pedidos")) {

            setContentView(R.layout.pref_produto);

            LinearLayout lData = (LinearLayout) findViewById(R.id.DataFilter);

            tvData = (TextView) findViewById(R.id.textData);

            tvData.setText(getRotuloFiltroDataPedidos());

            lData.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    final String names[] = {"Mais Recente", "Mais Antiga"};
                    alertDialog = new AlertDialog.Builder(FiltrarActivity.this);
                    LayoutInflater inflater = getLayoutInflater();
                    View convertView = (View) inflater.inflate(R.layout.dialog_data, null);
                    alertDialog.setView(convertView);
                    alertDialog.setTitle("Filtrar Data");
                    ListView lv = (ListView) convertView.findViewById(R.id.listView1);

                    ArrayAdapter<String> adapter = new ArrayAdapter<String>(FiltrarActivity.this, android.R.layout.simple_list_item_1, names);

                    final Dialog dialog = alertDialog.create();
                    dialog.show();

                    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            //your code


                            mSessao.put("filtro_pedidos_data", (position == 0) ? "DESC" : "ASC");

                            textValue = (TextView) findViewById(R.id.textData);
                            textValue.setText(getRotuloFiltroDataPedidos());

                            dialog.dismiss();


                        }
                    });

                    lv.setAdapter(adapter);

                }


            });


@Override
    public void onBackPressed() {

        Fragment fragment = getFragmentManager().findFragmentByTag("");
        if (fragment != null && fragment instanceof BackPressedListener) {
            ((BackPressedListener) fragment).onBackPressed();

        } else {
            super.onBackPressed();
            overridePendingTransition(R.anim.animation_back, R.anim.animation_back_leave);
        }
    }
}

0 个答案:

没有答案