content: package com.airsaid.android_pickerview_library;
  
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.util.Log;
  import android.view.KeyEvent;
  import android.view.View;
  import android.widget.Toast;
  
  import com.airsaid.pickerviewlibrary.CityPickerView;
  import com.airsaid.pickerviewlibrary.OptionsPickerView;
  import com.airsaid.pickerviewlibrary.TimePickerView;
  import com.airsaid.pickerviewlibrary.listener.OnSimpleCitySelectListener;
  
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.Locale;
  
  public class MainActivity extends AppCompatActivity {
  
      public static final String TAG = "MainActivity";
  
      private TimePickerView mTimePickerView;
      private CityPickerView mCityPickerView;
      private OptionsPickerView<String> mOptionsPickerView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          mCityPickerView = new CityPickerView(this);
          mTimePickerView = new TimePickerView(this, TimePickerView.Type.YEAR_MONTH_DAY);
          mOptionsPickerView = new OptionsPickerView<>(this);
      }
  
      public void selectCity(View v){
          // 设置点击外部是否消失
  //        mCityPickerView.setCancelable(true);
          // 设置滚轮字体大小
  //        mCityPickerView.setTextSize(18f);
          // 设置标题
  //        mCityPickerView.setTitle("我是标题");
          // 设置取消文字
  //        mCityPickerView.setCancelText("我是取消文字");
          // 设置取消文字颜色
  //        mCityPickerView.setCancelTextColor(Color.GRAY);
          // 设置取消文字大小
  //        mCityPickerView.setCancelTextSize(14f);
          // 设置确定文字
  //        mCityPickerView.setSubmitText("我是确定文字");
          // 设置确定文字颜色
  //        mCityPickerView.setSubmitTextColor(Color.BLACK);
          // 设置确定文字大小
  //        mCityPickerView.setSubmitTextSize(14f);
          // 设置头部背景
  //        mCityPickerView.setHeadBackgroundColor(Color.RED);
          mCityPickerView.setOnCitySelectListener(new OnSimpleCitySelectListener(){
              @Override
              public void onCitySelect(String prov, String city, String area) {
                  // 省、市、区 分开获取
                  Log.e(TAG, "省: " + prov + " 市: " + city + " 区: " + area);
              }
  
              @Override
              public void onCitySelect(String str) {
                  // 一起获取
                  Toast.makeText(MainActivity.this, "选择了：" + str, Toast.LENGTH_SHORT).show();
              }
          });
          mCityPickerView.show();
      }
  
      public void selectTime(View v){
          // TimePickerView 同样有上面设置样式的方法
          // 设置是否循环
  //        mTimePickerView.setCyclic(true);
          // 设置滚轮文字大小
  //        mTimePickerView.setTextSize(TimePickerView.TextSize.SMALL);
          // 设置时间可选范围(结合 setTime 方法使用,必须在)
  //        Calendar calendar = Calendar.getInstance();
  //        mTimePickerView.setRange(calendar.get(Calendar.YEAR) - 100, calendar.get(Calendar.YEAR));
          // 设置选中时间
  //        mTimePickerView.setTime(new Date());
          mTimePickerView.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {
              @Override
              public void onTimeSelect(Date date) {
                  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
                  Toast.makeText(MainActivity.this, format.format(date), Toast.LENGTH_SHORT).show();
              }
          });
          mTimePickerView.show();
      }
  
      public void selectOption(View v){
          mOptionsPickerView = new OptionsPickerView<>(this);
          final ArrayList<String> list = new ArrayList<>();
          list.add("男");
          list.add("女");
          // 设置数据
          mOptionsPickerView.setPicker(list);
          // 设置选项单位
  //        mOptionsPickerView.setLabels("性");
          mOptionsPickerView.setOnOptionsSelectListener(new OptionsPickerView.OnOptionsSelectListener() {
              @Override
              public void onOptionsSelect(int option1, int option2, int option3) {
                  String sex = list.get(option1);
                  Toast.makeText(MainActivity.this, sex, Toast.LENGTH_SHORT).show();
              }
          });
          mOptionsPickerView.show();
      }
  
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          if (keyCode == KeyEvent.KEYCODE_BACK) {
              if(mTimePickerView.isShowing()){
                  mTimePickerView.dismiss();
                  return true;
              }
  
              if(mCityPickerView.isShowing()){
                  mCityPickerView.dismiss();
                  return true;
              }
  
              if(mOptionsPickerView.isShowing()){
                  mOptionsPickerView.dismiss();
                  return true;
              }
          }
          return super.onKeyDown(keyCode, event);
      }
  }
  