Exemplo n.º 1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // 实例化 fragment布局
    View view = inflater.inflate(R.layout.fragment_update, container, false);

    // 查找界面 组件
    TextView tv_id = (TextView) view.findViewById(R.id.textView2_id);

    et_player = (EditText) view.findViewById(R.id.editText2_player);
    et_score = (EditText) view.findViewById(R.id.editText2_score);
    et_level = (EditText) view.findViewById(R.id.editText2_level);

    // 界面按钮
    Button button_save = (Button) view.findViewById(R.id.button_save);
    Button button_cancel = (Button) view.findViewById(R.id.button_cancel);

    // 注册监听事件
    button_save.setOnClickListener(this);
    button_cancel.setOnClickListener(this);

    // 组件内容填充
    tv_id.setText(String.valueOf(gamePlayer.getId()));
    et_player.setText(gamePlayer.getPlayer());
    et_score.setText(String.valueOf(gamePlayer.getScore()));
    et_level.setText(String.valueOf(gamePlayer.getLevel()));

    return view;
  }
Exemplo n.º 2
0
  // 数据提交到数据库
  private void save() {
    GamePlayer g = new GamePlayer();

    // 组件的输入内容添加 到数据库中
    g.setId(gamePlayer.getId());
    g.setPlayer(et_player.getText().toString());
    g.setScore(Integer.parseInt(et_score.getText().toString()));
    g.setLevel(Integer.parseInt(et_level.getText().toString()));

    // 调用 activity中的更新方法
    updateFragmentListener.update(g);
    getActivity().getFragmentManager().popBackStack(); // 出栈
  }