예제 #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();
  }
예제 #2
0
파일: Expr.java 프로젝트: thorntonrose/Expr
  @Override
  public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
    Log.d(TAG, "onEditorAction: actionId: " + actionId + ", keyEvent: " + keyEvent);

    if ((actionId == EditorInfo.IME_ACTION_DONE)
        || ((keyEvent != null) && (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
      Log.d(TAG, "onEditorAction: IME_ACTION_DONE || KEYCODE_ENTER");
      String input = textView.getText().toString().trim();

      if (input.length() > 0) {
        String result = "";

        try {
          result += calculator.calculate(input);
        } catch (Exception e) {
          result = "no result (" + e.getMessage() + ")";
        }

        if (listAdapter.getCount() > 0) {
          listAdapter.add("");
        }

        listAdapter.add(input + " =");
        if (input.indexOf("@") > -1) {
          listAdapter.add(calculator.getEquation() + " =");
        }
        listAdapter.add(result);
        listAdapter.notifyDataSetChanged();

        inputView.endBatchEdit();
        inputView.setText("");
        hideKeyboard();
      }
    }

    return false;
  }