tuttelikz

HearingTestMainFragment [+]

Dec 12th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.51 KB | None | 0 0
  1. package com.example.iptea.hearingclub;
  2.  
  3.  
  4. import android.content.Context;
  5. import android.os.Bundle;
  6. import android.support.annotation.NonNull;
  7. import android.support.annotation.Nullable;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.support.v4.app.Fragment;
  12. import android.widget.ArrayAdapter;
  13. import android.widget.Button;
  14. import android.widget.EditText;
  15. import android.widget.TextView;
  16. import android.widget.Toast;
  17.  
  18. import java.util.Date;
  19.  
  20. import io.realm.Realm;
  21. import io.realm.RealmConfiguration;
  22.  
  23.  
  24. /**
  25.  * A simple {@link Fragment} subclass.
  26.  */
  27. public class HearingTestMainFragment extends Fragment {
  28.  
  29.     TextView dateTextView;
  30.     Button btnSave;
  31.     EditText etMinHz, etMaxhz, etPerc;
  32.     Realm realm;
  33.     HearingResults savedHearingResults;
  34.  
  35.     //public static final RealmHelper helper;
  36.  
  37.     @Override
  38.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  39.                              Bundle savedInstanceState) {
  40.  
  41.  
  42.         realm = Realm.getDefaultInstance();
  43.         View root = inflater.inflate(R.layout.fragment_hearing_test_main, container, false);;
  44.  
  45.         //class init
  46.         savedHearingResults = new HearingResults();
  47.         //Realm init
  48.  
  49.  
  50. /*        Realm.init(getActivity());
  51.         realm.getDefaultInstance();*/
  52.  
  53.  
  54.         //realm = MainActivity.getRealm(getContext());
  55.         //Helper init
  56.         final RealmHelper helper = new RealmHelper(realm);
  57.  
  58.  
  59.         //View fragment = inflater.inflate(R.layout.fragment_hearing_test_main, container, false);;
  60.         btnSave = root.findViewById(R.id.btnSave);
  61.         etMinHz = root.findViewById(R.id.etMinHz);
  62.  
  63.  
  64.         btnSave.setOnClickListener(new View.OnClickListener() {
  65.  
  66.             @Override
  67.             public void onClick(View v)
  68.             {
  69.  
  70.                 savedHearingResults.setId(etMinHz.getText().toString());
  71.                 helper.save(savedHearingResults);
  72.                 etMinHz.setText("");
  73.  
  74.                 toastMessage("Sucessfully added");
  75.             }
  76.         });
  77.  
  78.         return root;
  79.         //return inflater.inflate(R.layout.fragment_hearing_test_main, container, false);
  80.     }
  81.  
  82.     @Override
  83.     public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  84.         super.onViewCreated(view, savedInstanceState);
  85.  
  86.     }
  87.  
  88.     @Override
  89.     public void onDestroyView() {
  90.         super.onDestroyView();
  91.         realm.close();
  92.     }
  93.  
  94.     private void toastMessage(String message) {
  95.         Toast.makeText(getContext(),message, Toast.LENGTH_SHORT).show();
  96.     }
  97.  
  98.  
  99. }
  100.  
  101.  
  102.  
  103. // Realm.init(getContext());
  104. // realm.getDefaultInstance();
  105.  
  106.  
  107.  
  108. //realm = MainActivity.getRealm(getActivity());
  109.  
  110.  
  111. /*        dateTextView = view.findViewById(R.id.tvCurDate);*/
  112.  
  113.  
  114. /*        etMaxhz = view.findViewById(R.id.etMaxHz);
  115.         etPerc = view.findViewById(R.id.etPerc);*/
  116.  
  117.  
  118.  
  119.  
  120. /*                HearingResults s = new HearingResults();
  121.                 //s.setId(new Date().toString());
  122.                 s.setId(etMinHz.getText().toString());
  123.                 s.setMinFrequency(etMinHz.getText().toString());
  124.                 s.setMaxFrequency(etMaxhz.getText().toString());
  125.                 s.setPercentage(etPerc.getText().toString());
  126.  
  127.                 RealmHelper helper = new RealmHelper(realm);
  128.                 helper.save(s);
  129.                 toastMessage("Sucessfully added");*/
  130.  
  131.  
  132.  
  133. /*    @Override
  134.     public void onDestroy() {
  135.         super.onDestroy();
  136.         realm.close();
  137.     }*/
Advertisement
Add Comment
Please, Sign In to add comment