SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. popUp = popupWindows(true);
  2. popUp.showAsDropDown(txtYear, 0, 0);
  3. --------------------------
  4.   private PopupWindow popupWindows(boolean isYear) {
  5.  
  6.         ArrayList<String> mListArray = new ArrayList<>();
  7.  
  8.         if (isYear) {
  9.             Calendar calendar = Calendar.getInstance();
  10.             int year = calendar.get(Calendar.YEAR);
  11.             for (int i = 0; i < 20; i++) {
  12.                 mListArray.add((year + i) + "");
  13.             }
  14.         } else {
  15.  
  16.             for (int i = 1; i <= 12; i++) {
  17.  
  18.                 mListArray.add(i < 10 ? "0" + i : "" + i);
  19.             }
  20.  
  21.  
  22.         }
  23.  
  24.         final PopupWindow popupWindow = new PopupWindow(getContext());
  25.  
  26.         ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), R.layout.custom_spinner_layout, mListArray);
  27.         final ListView listViewSort = new ListView(getContext());
  28.         listViewSort.setAdapter(adapter);
  29.  
  30.         listViewSort.setOnItemClickListener((adapterView, view, i, l) -> {
  31.             if (isYear) {
  32.                 txtYear.setText("" + mListArray.get(i));
  33.             } else {
  34.                 txtMonth.setText("" + mListArray.get(i));
  35.             }
  36.  
  37.             popupWindow.dismiss();
  38.         });
  39.         popupWindow.setFocusable(true);
  40.         int width = (int) getResources().getDimension(R.dimen._130sdp);
  41.         popupWindow.setWidth(width);
  42.         popupWindow.getAnimationStyle();
  43.         popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
  44.         popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
  45.         popupWindow.setContentView(listViewSort);
  46.         return popupWindow;
  47.     }
  48.  @estaticdev123
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top