Beispiel #1
0
  private void initGameRecyclerView() {

    layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
    gameRecyclerView.setLayoutManager(layoutManager);

    gameAdapter.setOnItemClickListener(this);
    gameRecyclerView.setAdapter(gameAdapter);
    gameRecyclerView.setHasFixedSize(true);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_consulta_tabela_preco);

    atoolbar = (Toolbar) (findViewById(R.id.tb_main));
    atoolbar.setTitle("Consulta Tabela de Preço");

    setSupportActionBar(atoolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    RecyviewTabelapreco = (RecyclerView) findViewById(R.id.RecyviewTabelaItempreco);

    produtodao = new ProdutoDao(this);

    if (getIntent().getExtras() != null)
      selecionandoTabela = getIntent().getExtras().getBoolean("selecionar_TabelaItemPreco", false);

    final StaggeredGridLayoutManager llm =
        new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
    llm.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
    RecyviewTabelapreco.setLayoutManager(llm);

    adapterTabelaitempreco =
        new AdapterConsultaTabelapreco(this, new ArrayList<Produtos>()) {
          @Override
          protected void onItemClickListener(int adapterPosition, int layoutPosition) {
            // evento de click simples

            Produtos produto = adapterTabelaitempreco.getItems().get(adapterPosition);
            if (selecionandoTabela) {
              Intent data = new Intent();
              data.putExtra("Produto_id", produto.getIdproduto());
              setResult(RESULT_OK, data);
              finish();
            } else {
              idProduto = produto.getIdproduto();
              nomeProduto = produto.getDescricao();

              consultaTabelaPreco(produto);
            }
          }

          @Override
          protected boolean onLongItemClickListener(int adapterPosition, int layoutPosition) {
            // evento e click longo
            Produtos produto = adapterTabelaitempreco.getItems().get(adapterPosition);
            idProduto = produto.getIdproduto();
            nomeProduto = produto.getDescricao();

            consultaTabelaPreco(produto);

            return true;
          }
        };

    RecyviewTabelapreco.setAdapter(adapterTabelaitempreco);

    consultaTabelaitem();

    getDadosSearch(this.getIntent());
  }