daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Sep 9th, 2018 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class create extends AppCompatActivity {
  2.  
  3.  
  4.     private LinearLayout mLinearLayout;
  5.     private ArrayList<SearchableSpinner> mSpinners;
  6.     private List<AppCompatButton> mButtons = new ArrayList<>();
  7.     private List<CheckBox> mCheckboxes = new ArrayList<>();
  8.     private List<TextView> mTextviews = new ArrayList<>();
  9.     private List<EditText> mEdittexts = new ArrayList<>();
  10.     private List<View> mViews = new ArrayList<>();
  11.     private Map<String, String> numberItemValues = new HashMap<>();
  12.     private Spinner spinner;
  13.     private TextView textview;
  14.     private CheckBox checkbox;
  15.     List<String> itemList = new ArrayList<>();
  16.     LinearLayout verticallayout,horizontalLayout;
  17.     public static final String MY_PREFS_NAME = "MyPrefsFile";
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.     @Override
  25.     protected void onCreate(Bundle savedInstanceState) {
  26.         super.onCreate(savedInstanceState);
  27.         setContentView(R.layout.activity_create);
  28.         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  29.         findViewById(R.id.my_linearLayout).requestFocus();
  30.  
  31.         verticallayout = findViewById(R.id.verticalLayout); //got
  32.  
  33.  
  34.  
  35.  
  36.  
  37.         //Arrays
  38.         ArrayList<String> items = new ArrayList<>();
  39.         items.add(String.valueOf(mSpinners)); // add you selected item
  40.         mSpinners = new ArrayList<>();
  41.  
  42.  
  43.  
  44.  
  45.         //Initializing Variables Here
  46.         mLinearLayout = findViewById(R.id.my_linearLayout);
  47.         //verticallayout = findViewById(R.id.verticalLayout);
  48.         textview = findViewById(R.id.textview);
  49.         checkbox = findViewById(R.id.checkbox);
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.         SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
  59.  
  60.         try {
  61.             JSONArray jsonArray2 = new JSONArray(prefs.getString("key", null));
  62.             for (int i = 0; i < jsonArray2.length(); i++) {
  63.  
  64.  
  65.  
  66.                 final Spinner spinner = makeSpinner();
  67.                 mLinearLayout.addView(spinner);
  68.                 mSpinners.add((SearchableSpinner) spinner);
  69.  
  70.  
  71.                 final View newView = makeView();
  72.                 //Add a new view
  73.                 mLinearLayout.addView(newView);
  74.                 mViews.add(newView);
  75.  
  76.  
  77.                 final EditText newEdittext = makeEdittext();
  78.                 mLinearLayout.addView(newEdittext);
  79.                 mEdittexts.add(newEdittext);
  80.  
  81.  
  82.  
  83.                 final CheckBox newCheckbox = makeCheckbox();
  84.                 mLinearLayout.addView(newCheckbox);
  85.  
  86.                 //TODO add checkbox to your list
  87.                 mCheckboxes.add(newCheckbox);
  88.  
  89.  
  90.                 final TextView newTextview = makeTextview();
  91.                 mLinearLayout.addView(newTextview);
  92.                 mTextviews.add(newTextview);
  93.  
  94.  
  95.  
  96.                 //TODO Add the spinner on item selected listener to get selected items
  97.                 spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  98.                     @Override
  99.                     public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
  100.                         String currentItem = itemList.get(position);
  101.                         String aisleNumber = numberItemValues.get(currentItem);
  102.                         //TODO you can use the above aisle number to add to your text view
  103.                         //mTextviews.get(mTextviews.size() -1).setText(aisleNumber);
  104.                         newTextview.setText(aisleNumber);
  105.                     }
  106.  
  107.                     @Override
  108.                     public void onNothingSelected(AdapterView<?> parentView) {
  109.                         //  do nothing
  110.                     }
  111.                 });
  112.  
  113.                 final int listSize = mViews.size();
  114.  
  115.                 //TODO DELETIN ITEM
  116.                 newView.setOnClickListener(new View.OnClickListener() {
  117.                     //start
  118.                     @Override
  119.                     public void onClick(View view) {
  120.  
  121.                         //when the 'new button' is pressed, alert shows if you are sure you want to delete the item or not.
  122.  
  123.                         final View.OnClickListener context = this;
  124.  
  125.  
  126.                         AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(create.this);
  127.  
  128.  
  129.                         // set title
  130.                         alertDialogBuilder.setTitle("Delete Item");
  131.  
  132.                         // set dialog message
  133.                         alertDialogBuilder
  134.                                 .setMessage("Are you sure you want to delete this item?")
  135.                                 .setCancelable(false)
  136.                                 .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  137.                                     public void onClick(DialogInterface dialog, int id) {
  138.                                         // if this button is clicked, close
  139.                                         // current activity
  140.  
  141.  
  142.                                         if (listSize > 0) {
  143.  
  144.                                             mCheckboxes.get(listSize - 1).setVisibility(View.GONE);
  145.                                             mSpinners.get(listSize - 1).setVisibility(View.GONE);
  146.                                             mViews.get(listSize - 1).setVisibility(View.GONE);
  147.                                             mTextviews.get(listSize - 1).setVisibility(View.GONE);
  148.                                             mEdittexts.get(listSize - 1).setVisibility(View.GONE);
  149.                                             Toast.makeText(getBaseContext(), "Item removed.", Toast.LENGTH_SHORT).show();
  150.  
  151.                                         }
  152.  
  153.  
  154.                                     }
  155.                                 })
  156.                                 .setNegativeButton("No", new DialogInterface.OnClickListener() {
  157.                                     public void onClick(DialogInterface dialog, int id) {
  158.                                         // if this button is clicked, just close
  159.                                         // the dialog box and do nothing
  160.                                         dialog.cancel();
  161.                                     }
  162.                                 });
  163.  
  164.                         // create alert dialog
  165.                         AlertDialog alertDialog = alertDialogBuilder.create();
  166.  
  167.                         // show it
  168.                         alertDialog.show();
  169.  
  170.  
  171.                     }
  172.                 });
  173.  
  174.  
  175.  
  176.  
  177.  
  178.                 int positionOfSpinner = (int) jsonArray2.get(i);
  179.                 spinner.setSelection(positionOfSpinner);
  180.             }
  181.         } catch (Exception e) {
  182.             e.printStackTrace();
  183.         }
  184.  
  185.         //end of shared pref  code
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.         //TODO FAB BUTTON
  195.         FloatingActionButton floatingActionButton =
  196.                 (FloatingActionButton) findViewById(R.id.fab);
  197.  
  198.  
  199.         floatingActionButton.setOnClickListener(new View.OnClickListener() {
  200.             @Override
  201.             public void onClick(View view) {
  202.                 Toast.makeText(getBaseContext(), "Item added!", Toast.LENGTH_SHORT).show();
  203.                 spinner = findViewById(R.id.spinner);
  204.  
  205.  
  206.  
  207.                 // Handle ze click.
  208.                 final Spinner spinner = makeSpinner();
  209.                 mLinearLayout.addView(spinner);
  210.                 mSpinners.add((SearchableSpinner) spinner);
  211.  
  212.  
  213.  
  214.                 LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) spinner.getLayoutParams();
  215.                 layoutParams.setMargins(5, 100, 10, 0); //top 70
  216.  
  217.                 Resources resources = getResources();
  218.                 DisplayMetrics metrics = resources.getDisplayMetrics();
  219.  
  220.                 layoutParams.height = (int) (70 * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT)); //80
  221.                 layoutParams.width = (int) (240 * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT)); //240
  222.                 spinner.setLayoutParams(layoutParams);
  223.  
  224.                 final View newView = makeView();
  225.                 mLinearLayout.addView(newView);
  226.                 mViews.add(newView);
  227.  
  228.  
  229.                 final EditText newEdittext = makeEdittext();
  230.                 mLinearLayout.addView(newEdittext);
  231.                 mEdittexts.add(newEdittext);
  232.  
  233.                 final int listSize = mViews.size();
  234.  
  235.                 //code for deleting the said item.
  236.  
  237.  
  238.  
  239.                 newView.setOnClickListener(new View.OnClickListener() {
  240.                     //start
  241.                     @Override
  242.                     public void onClick(View view) {
  243.  
  244.                         //when the 'new button' is pressed, alert shows if you are sure you want to delete the item or not.
  245.  
  246.                         final View.OnClickListener context = this;
  247.  
  248.  
  249.                         AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(create.this);
  250.  
  251.  
  252.                         // set title
  253.                         alertDialogBuilder.setTitle("Delete Item");
  254.  
  255.                         // set dialog message
  256.                         alertDialogBuilder
  257.                                 .setMessage("Are you sure you want to delete this item?")
  258.                                 .setCancelable(false)
  259.                                 .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  260.                                     public void onClick(DialogInterface dialog, int id) {
  261.                                         // if this button is clicked, close
  262.                                         // current activity
  263.  
  264.  
  265.                                         if (listSize > 0) {
  266.  
  267.                                             mCheckboxes.get(listSize - 1).setVisibility(View.GONE);
  268.                                             mSpinners.get(listSize - 1).setVisibility(View.GONE);
  269.                                            // mSpinners.remove(listSize - 1);
  270.                                             mViews.get(listSize - 1).setVisibility(View.GONE);
  271.                                             mTextviews.get(listSize - 1).setVisibility(View.GONE);
  272.                                             mEdittexts.get(listSize - 1).setVisibility(View.GONE);
  273.                                             Toast.makeText(getBaseContext(), "Item removed.", Toast.LENGTH_SHORT).show();
  274.  
  275.                                         }
  276.                                     }
  277.                                 })
  278.                                 .setNegativeButton("No", new DialogInterface.OnClickListener() {
  279.                                     public void onClick(DialogInterface dialog, int id) {
  280.                                         // if this button is clicked, just close
  281.                                         // the dialog box and do nothing
  282.                                         dialog.cancel();
  283.                                     }
  284.                                 });
  285.  
  286.                         // create alert dialog
  287.                         AlertDialog alertDialog = alertDialogBuilder.create();
  288.  
  289.                         // show it
  290.                         alertDialog.show();
  291.  
  292.  
  293.                     }
  294.                 });
  295.  
  296.                 //Add a new checkbox
  297.                 final CheckBox newCheckbox = makeCheckbox();
  298.                 mLinearLayout.addView(newCheckbox);
  299.  
  300.                 //TODO add checkbox to your list
  301.                 mCheckboxes.add(newCheckbox);
  302.  
  303.  
  304.                 final TextView newTextview = makeTextview();
  305.                 mLinearLayout.addView(newTextview);
  306.                 mTextviews.add(newTextview);
  307.  
  308.                 //TODO Add the spinner on item selected listener to get selected items
  309.                 spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  310.                     @Override
  311.                     public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
  312.                         String currentItem = itemList.get(position);
  313.                         String aisleNumber = numberItemValues.get(currentItem);
  314.                         //TODO you can use the above aisle number to add to your text view
  315.                         //mTextviews.get(mTextviews.size() -1).setText(aisleNumber);
  316.                         newTextview.setText(aisleNumber);
  317.                     }
  318.  
  319.                     @Override
  320.                     public void onNothingSelected(AdapterView<?> parentView) {
  321.                         //  code here, do nothing
  322.                     }
  323.  
  324.                 });
  325.  
  326.  
  327.             }
  328.         });
  329.  
  330.     }
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.     //TODO OVERFLOW MENU
  351.     @Override
  352.     public boolean onCreateOptionsMenu(Menu menu) {
  353.         // Inflate the menu; this adds items to the action bar if it is present.
  354.         getMenuInflater().inflate(R.menu.create_menu, menu);
  355.         return true;
  356.     }
  357.  
  358.     @Override
  359.     public boolean onOptionsItemSelected(MenuItem item) {
  360.  
  361.         int id = item.getItemId();
  362.  
  363.         if (id == R.id.action_settings) {
  364.             /*Intent startSettingsActivity = new Intent(this, AppCompatPreferenceActivity.class);
  365.             startActivity(startSettingsActivity);
  366.             //start the settings activity here.*/
  367.  
  368.             startActivity(new Intent(create.this, settings.class));
  369.  
  370.  
  371.  
  372.  
  373.  
  374.             return true;
  375.         }
  376.  
  377.  
  378.         else if (id == R.id.action_delete) {
  379.             //code to delete list here.
  380.  
  381.             SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
  382.  
  383.             editor.clear();
  384.             editor.commit();
  385.  
  386.             Toast.makeText(getBaseContext(), "List removed.", Toast.LENGTH_SHORT).show();
  387.             return true;
  388.         }
  389.  
  390.  
  391.         else if (id ==R.id.action_help)  {
  392.  
  393.  
  394.             // setup the alert builder
  395.             AlertDialog.Builder builder = new AlertDialog.Builder(this);
  396.             builder.setTitle("Help");
  397.             builder.setMessage("To use this app, first go to Create your Shopping List.\n" +
  398.                     "Here, you can add items to your list. Once you have added all items, you can click the menu at the top right corner (or if it doesnt appear press your menu button beside your home button on your device, then click View your List.\n" +
  399.                     "This will take you to the screen where you can view you shopping list with the items in aisle order to make your shop much easier.\n" +
  400.                     "You can still add items at this point. Press the white background of each item to delete the item if you wish.");
  401.  
  402.             // add a button
  403.             builder.setPositiveButton("OK", null);
  404.  
  405.             // create and show the alert dialog
  406.             AlertDialog dialog = builder.create();
  407.             dialog.show();
  408.  
  409.  
  410.             return true;
  411.  
  412.         }
  413.  
  414.  
  415.  
  416.  
  417.         else if (id == R.id.action_gotoview) {
  418.  
  419.  
  420.             //takes the size of the list of spinners, for reference
  421.             ArrayList<Integer> spinnerList = new ArrayList<>();
  422.             for(int i = 0; i < mSpinners.size(); i++) {
  423.                 spinnerList.add(mSpinners.get(i).getSelectedItemPosition());
  424.  
  425.             }
  426.             Bundle newBundle = new Bundle();
  427.             newBundle.putIntegerArrayList("arraylist", spinnerList);
  428.             Intent newIntent = new Intent(create.this, viewscreen.class);
  429.             newIntent.putExtra("extraBundle", newBundle);
  430.  
  431.             startActivity(newIntent);
  432.  
  433.  
  434.  
  435.             //code to go to view screen, aka intent
  436.             return true;
  437.         }
  438.  
  439.  
  440.  
  441.         return super.onOptionsItemSelected(item);
  442.     }
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.     public void createRow(View view){
  450.  
  451.         createRow(); //got
  452.  
  453.     }
  454.  
  455.  
  456.     private void createRow() { //got
  457.  
  458.         horizontalLayout = new LinearLayout(this);
  459.  
  460.         LinearLayout.LayoutParams horizontalParams = new LinearLayout.LayoutParams(
  461.                 LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  462.         horizontalLayout.setOrientation(LinearLayout.HORIZONTAL);
  463.         horizontalLayout.setLayoutParams(horizontalParams);
  464.  
  465.         makeEdittext();
  466.         makeCheckbox();
  467.         makeView();
  468.  
  469.         verticallayout.addView(horizontalLayout);
  470.     }
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.     //DUPLICATING ITEMS WHEN FAB IS PRESSED//
  479.     private CheckBox makeCheckbox() {
  480.         //Create new Checkbox
  481.         CheckBox checkbox = new CheckBox(this);
  482.  
  483.         // Setup layout
  484.         LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
  485.                 LinearLayout.LayoutParams.MATCH_PARENT,
  486.                 LinearLayout.LayoutParams.WRAP_CONTENT);
  487.  
  488.  
  489.         //setup relative layout for the positioning of the objects
  490.         Resources resources = getResources();
  491.         DisplayMetrics metrics = resources.getDisplayMetrics();
  492.         RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams((int) (70 * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT)), (int) (240 * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT)));
  493.         relativeParams.addRule(RelativeLayout.RIGHT_OF, R.id.textview);
  494.  
  495.         checkbox.setLayoutParams(relativeParams);
  496.         checkbox.setLayoutParams(layoutParams);
  497.  
  498.  
  499.  
  500.   /*      LinearLayout.LayoutParams checkParams = new LinearLayout.LayoutParams(
  501.                 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  502.         checkParams.setMargins(10, 10, 10, 10);
  503.         checkParams.gravity = Gravity.LEFT;
  504.  
  505.         checkbox.setLayoutParams(checkParams);
  506.         horizontalLayout.addView(checkbox);*/
  507.  
  508.  
  509.         return checkbox;
  510.     }
  511.  
  512.  
  513.  
  514.     private TextView makeTextview() {
  515.         //create new textview
  516.         TextView textview = new TextView(this);
  517.  
  518.         //setup layout
  519.  
  520.         LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
  521.                 LinearLayout.LayoutParams.MATCH_PARENT,
  522.                 LinearLayout.LayoutParams.WRAP_CONTENT);
  523.         textview.setLayoutParams(layoutParams);
  524.         textview.setTextSize(30);
  525.  
  526.         return textview;
  527.     }
  528.  
  529.  
  530.  
  531.     private EditText makeEdittext() {
  532.         //create new edittext
  533.         EditText edittext = new EditText(this);
  534.  
  535.         //setup layout
  536.         final LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(70, 50); // Width , height
  537.         edittext.setLayoutParams(lparams);
  538.  
  539.  
  540.        /* LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(
  541.                 LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  542.         editParams.setMargins(10, 10, 10, 10);*/
  543.         lparams.width = 70;
  544.         lparams.height = 50;
  545.  
  546.         edittext.setLayoutParams(lparams);
  547.  
  548. /*
  549.         edittext.setLayoutParams(editParams);
  550.         horizontalLayout.addView(edittext);*/
  551.  
  552.         edittext.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
  553.         edittext.setHint("qty");
  554.  
  555.         return edittext;
  556.  
  557.     }
  558.  
  559.  
  560.  
  561.     private View makeView() {
  562.         //create new View
  563.  
  564.         View view = new View(this);
  565.         view.setBackgroundColor(Color.parseColor("#ffffff"));
  566.         LinearLayout.LayoutParams layoutParams =  new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 100);
  567.         new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, 50);
  568.  
  569.  
  570.         view.setLayoutParams(layoutParams);
  571.  
  572.  
  573.         view.setClickable(true);
  574.  
  575.         //view.setLayoutParams(layoutParams);
  576.  
  577.  
  578.         //setup layout
  579.  
  580.         return view;
  581.  
  582.  
  583.     }
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.     private Spinner makeSpinner() {
  599.         //opens csv
  600.         InputStream inputStream = getResources().openRawResource(R.raw.shopitems);
  601.         CSVFile csvFile = new CSVFile(inputStream);
  602.         //TODO I made this variable global, declared it at the very top of this file
  603.         itemList = csvFile.read();
  604.  
  605.         //Create new spinner
  606.         // SearchableSpinner spinner = (SearchableSpinner) new Spinner(this, Spinner.MODE_DROPDOWN);
  607.         SearchableSpinner spinner = new SearchableSpinner(this);
  608.  
  609.  
  610.         // Setup layout
  611.  
  612.     /*    LinearLayout.LayoutParams spinnerParams = new LinearLayout.LayoutParams(
  613.                 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  614.         spinnerParams.setMargins(10, 10, 10, 10);
  615.         spinnerParams.gravity = Gravity.LEFT;
  616.  
  617.         Resources resources = getResources();
  618.         DisplayMetrics metrics = resources.getDisplayMetrics();
  619.  
  620.         spinnerParams.height = (int) (70 * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT)); //80
  621.         spinnerParams.width = (int) (240 * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT)); //240
  622.  
  623.         spinner.setLayoutParams(spinnerParams);
  624.         horizontalLayout.addView(spinner);*/
  625.  
  626.         LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
  627.                 LinearLayout.LayoutParams.MATCH_PARENT,
  628.                 LinearLayout.LayoutParams.WRAP_CONTENT);
  629.         spinner.setLayoutParams(layoutParams);
  630.  
  631.  
  632.  
  633.         MyListAdapter adapter = new MyListAdapter(this, R.layout.listrow, R.id.txtid, itemList);
  634.  
  635.  
  636.         spinner.setAdapter(adapter);
  637.  
  638.         //Add it to your list of spinners so you can retrieve their data when you click the getSpinner button
  639.         //mSpinners.add(spinner);
  640.         return spinner;
  641.     }
  642.  
  643.  
  644.  
  645.     private class CSVFile {
  646.         InputStream inputStream;
  647.  
  648.         public CSVFile(InputStream inputStream) {
  649.             this.inputStream = inputStream;
  650.         }
  651.  
  652.         public List<String> read() {
  653.  
  654.             List<String> resultList = new ArrayList<String>();
  655.             BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
  656.             try {
  657.                 String line;
  658.                 while ((line = reader.readLine()) != null) {
  659.                     String[] row = line.split(",");
  660.                     //TODO I edited this part so that you'd add the values in our new hash map variable
  661.                     numberItemValues.put(row[1], row[0]);
  662.                     resultList.add(row[1]);
  663.                 }
  664.             } catch (IOException e) {
  665.                 Log.e("Main", e.getMessage());
  666.             } finally {
  667.                 try {
  668.                     inputStream.close();
  669.                 } catch (IOException e) {
  670.                     Log.e("Main", e.getMessage());
  671.                 }
  672.             }
  673.             return resultList;
  674.         }
  675.     }
  676.  
  677.  
  678.     //on stop, the things are saved into shared prefs
  679.     @Override
  680.     protected void onStop () {
  681.  
  682.         //public static final String MY_PREFS_NAME = "MyPrefsFile";
  683.         SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
  684.         JSONArray jsonArray = new JSONArray();
  685.         for(int i = 0; i < mSpinners.size(); i++) {
  686.             jsonArray.put(mSpinners.get(i).getSelectedItemPosition());
  687.  
  688.         }
  689.  
  690.         editor.putString("key", jsonArray.toString());
  691.         editor.apply();
  692.  
  693.  
  694.         super.onStop();
  695.     }
  696.  
  697. }
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