Exemplo n.º 1
0
  public void addToList(String name) {
    Consumptie c = null;
    for (Consumptie d : consumpties) {
      if (d.getNaam() == name) c = d;
    }
    if (c != null) {
      LayoutInflater inflater = LayoutInflater.from(findViewById(R.id.drinklist).getContext());
      LinearLayout v =
          (LinearLayout) inflater.inflate(R.layout.fragment_drink_list_item, null, false);
      ((TextView) v.findViewById(R.id.drinkName)).setText(c.getNaam());
      ((TextView) v.findViewById(R.id.drinkAmount)).setText(String.valueOf(c.getHoeveelheid()));

      ((LinearLayout) findViewById(R.id.drinklist)).addView(v);
    } else {
      System.out.println("swag: null");
    }
  }
Exemplo n.º 2
0
  public void addDrink(View v) {

    // set up dialog
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_consumptie);
    dialog.setTitle("");
    dialog.setCancelable(true);
    // there are a lot of settings, for dialog, check them all out!

    int kosten = 0;
    switch (v.getId()) {
      case R.id.OnePaultje:
        kosten = 1;
        break;
      case R.id.TwoPaultje:
        kosten = 2;
        break;
      case R.id.ThreePaultje:
        kosten = 3;
        break;
    }
    GridLayout grid = (GridLayout) dialog.findViewById(R.id.gridLayout);
    for (Consumptie c : consumpties) {
      if (c.getKosten() == kosten) {
        Button b = new Button(dialog.getContext());
        b.setText(c.getNaam());
        b.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                dialog.cancel();
                Button but = (Button) v;
                addToList(but.getText().toString());
              }
            });
        grid.addView(b);
      }
    }
    dialog.show();
  }