Ejemplo n.º 1
0
  private void setMineralLists(Sector sector) {
    // Populate the list with the initial data
    // Remove the ones we don't want
    mineralList.clear();
    mineralList.addAll(Static.mineralList);

    // Grab the ore list for later
    ArrayAdapter<String> oreListAdapter =
        new ArrayAdapter<String>(
            this, android.R.layout.simple_list_item_1, new ArrayList<String>());
    ((ListView) findViewById(R.id.oreList)).setAdapter(oreListAdapter);

    // Add and remove the needed things from the lists
    for (Mineral mineral : sector.getMinerals()) {
      mineralList.remove(mineral.getMineral());

      oreListAdapter.add(mineral.getMineral());
    }

    // Check to see if the mineral list is empty. If so add the emtpy mineral
    if (mineralList.size() == 0) mineralList.add(emptyMineralString);

    mineralAdapter.notifyDataSetChanged();
    oreListAdapter.notifyDataSetChanged();
  }
Ejemplo n.º 2
0
  /**
   * Handles what to do when the add button is clicked. Namely adding the selected mineral to the
   * sector and updating the lists after.
   */
  public void onClick(View v) {
    Mineral mineral = new Mineral();
    String mineralName = (String) ((Spinner) findViewById(R.id.mineralList)).getSelectedItem();

    if (!mineralName.equals(emptyMineralString)) {
      mineral.setMineral(mineralName);

      data.addMineralToSector(currentSector, mineral);
      setMineralLists(currentSector);
    }
  }