示例#1
0
  private void showCityDialog() {
    View view = LayoutInflater.from(this).inflate(R.layout.dialog_city, null);

    final EditText et = (EditText) view.findViewById(R.id.et_dialog_city);
    Button btn = (Button) view.findViewById(R.id.btn_dialog_city);

    final AlertDialog dialog =
        DialogUtils.showAlertDialog(this, "设置所在城市", null, view, null, "返回", null);

    et.setText(PreferenceUtils.getString(MainActivity.this, "city", "北京"));

    btn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String city = et.getText().toString().trim();

            if (TextUtils.isEmpty(city)) {
              et.setError("所在城市不能为空");

            } else {
              if (PreferenceUtils.putString(MainActivity.this, "city", city)) {

                MainActivity.this.showSnaker(drawer, "保存成功", null, null);

                dialog.dismiss();
              }
            }
          }
        });
  }
示例#2
0
  @SuppressWarnings("StatementWithEmptyBody")
  @Override
  public boolean onNavigationItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.nav_tv:
        toolbar.setTitle("电视节目");

        TVFragment tvFragment = TVFragment.newInstance("", "");
        fragmentTrans(tvFragment);

        break;
      case R.id.nav_basket:
        toolbar.setTitle("NBA赛事");

        BasketFragment basketFragment = new BasketFragment();
        fragmentTrans(basketFragment);

        break;
      case R.id.nav_foot:
        toolbar.setTitle("足球联赛");

        FootFragment footFragment = FootFragment.newInstance("", "");
        fragmentTrans(footFragment);

        break;
      case R.id.nav_movie:
        toolbar.setTitle("近期影视");

        MovieFragment movieFragment = MovieFragment.newInstance("", "");
        fragmentTrans(movieFragment);

        break;
      case R.id.nav_theme:
        DialogUtils.showThemeDialog(this);

        break;
      case R.id.nav_settings:
        showCityDialog();

        break;
    }
    drawer.closeDrawer(GravityCompat.START);
    return true;
  }