Searchable Activity with Recycler View

Asked

Viewed 105 times

1

I have a Searchable Activity that is being used in two different activitys, but in the result that generates a Recycler View I would like to treat the click, to know what was the generating activity. But when using the getLocalClassName() method inside Adapter, it always returns the name of Searchable Activity to me.

Is there any other way to know which the generator Activity (before searchable)?

Follow the codes used.

Menu of the Activity Criapedidoactivity

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_criar_pedido, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView;
    MenuItem item = menu.findItem(R.id.action_searchable_activity);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        searchView = (SearchView) item.getActionView();
    } else {
        searchView = (SearchView) MenuItemCompat.getActionView(item);
    }
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setQueryHint(getResources().getString(R.string.search_hint));
    return true;
}

Searchable Activity

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_searchable_clientes);

    // TOOLBAR
    mToolbar = (Toolbar) findViewById(R.id.toolbarClientes);
    mToolbar.setTitle("Resultado de pesquisa - Clientes");
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (RecyclerView) findViewById(R.id.listaClientes);
    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);
    // use a linear layout manager
    mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);

    clContainer = (CoordinatorLayout) findViewById(R.id.cl_container);

    hendleSearch(getIntent());
}

public void hendleSearch(Intent intent) {
    intent.getComponent();
    if (Intent.ACTION_SEARCH.equalsIgnoreCase(intent.getAction())) {
        String q = intent.getStringExtra(SearchManager.QUERY);
        filtroClientes(q);
    }
}

Adapter

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    // each data item is just a string in this case
    public TextView txtRazaoSocial;
    public TextView txtEndereco;
    public TextView txtBairro;
    public TextView txtCidade;


    public ViewHolder(View itemView) {
        super(itemView);
        itemView.setOnClickListener(this);
        txtRazaoSocial = (TextView) itemView.findViewById(R.id.txtRazaoSocial);
        txtEndereco = (TextView) itemView.findViewById(R.id.txtEndereco);
        txtBairro = (TextView) itemView.findViewById(R.id.txtBairro);
        txtCidade = (TextView) itemView.findViewById(R.id.txtCidade);
    }

    @Override
    public void onClick(View view) {
        if (clientesActivity.getLocalClassName().equals("activity.CriarPedidoActivity")) {
            Cliente clienteSelecionado = mDataset.get(getPosition());
            PedidoCabecalho pedidoCabecalho = new PedidoCabecalho();
            pedidoCabecalho.setCliente(clienteSelecionado);
            Intent irParaPedidoItem = new Intent(clientesActivity, CriarPedidoItemActivity.class);
            irParaPedidoItem.putExtra(CLIENTE_SEELECIONADO, pedidoCabecalho);
            clientesActivity.startActivity(irParaPedidoItem);
        } else {
            Cliente clienteSelecionado = mDataset.get(getPosition());
            Intent irParaDetalhesCliente = new Intent(clientesActivity, DetalheClienteActivity.class);
            irParaDetalhesCliente.putExtra(CLIENTE_SEELECIONADO, clienteSelecionado);
            clientesActivity.startActivity(irParaDetalhesCliente);
        }
    }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.