示例#1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_team);

    _playerList = (LinearLayout) findViewById(R.id.playerList);
    findViewById(R.id.addPlayer).setOnClickListener(addPlayerListener);
    findViewById(R.id.editPlayer).setOnClickListener(editPlayerListener);
    findViewById(R.id.deletePlayer).setOnClickListener(deletePlayerListener);
    findViewById(R.id.confirmTeam).setOnClickListener(confirmTeamListener);

    String teamEditor = getIntent().getStringExtra(StaticFinalVars.CREATE_EDIT);
    _sportType = getIntent().getStringExtra(StaticFinalVars.SPORT_TYPE);
    _loggedIn = getIntent().getBooleanExtra(StaticFinalVars.LOGIN_STATUS, false);

    // databases
    if (_sportType.equals("basketball")) {
      _db = new BasketballDatabaseHelper(this);
    } else if (_sportType.equals("soccer")) {
      _db = new SoccerDatabaseHelper(this);
    } else if (_sportType.equals("hockey")) {
      _db = new HockeyDatabaseHelper(this);
    } else if (_sportType.equals("football")) {
      _db = new FootballDatabaseHelper(this);
    }

    if (!teamEditor.equals("")) {
      _editing = true;

      // Pull info from database and add to scroll view
      ArrayList<Teams> teams = (ArrayList<Teams>) _db.getAllTeams();
      for (Teams t : teams) {
        if (t.gettname().equals(teamEditor)) {
          _curTeam = t;
          t_id = _curTeam.gettid();
          break;
        }
      }

      // pull abbr and coach name
      ((EditText) findViewById(R.id.teamNameEditText)).setText(teamEditor);
      ((EditText) findViewById(R.id.teamAbbrEditText)).setText(_curTeam.getabbv());
      ((EditText) findViewById(R.id.coachNameEditText)).setText(_curTeam.getcname());

      // get List of players on curTeam from database
      ArrayList<Players> players = (ArrayList<Players>) _db.getPlayersTeam2(t_id);
      // add players names and numbers to view
      for (Players p : players) {
        _playerList.addView(newPlayerItem(p.getpname(), ((Integer) p.getpnum()).toString()));
      }

      _oldTeamName = teamEditor;
    }
  }
示例#2
0
  public int updatePlayer(Players player) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_T_ID, player.gettid());
    values.put(KEY_P_NAME, player.getpname());
    values.put(KEY_P_NUM, player.getpnum());
    if (!_local) {
      _net.updatePlayer(player);
    }
    return db.update(
        TABLE_PLAYERS, values, KEY_P_ID + " = ?", new String[] {String.valueOf(player.getpid())});
  }