android - Want to combine redundant Methods of pulling user/patient images into one method -


i have 9 of imageviews set in xml layout. application pulls images directly folder on device , loads image onto imageviews. because of redundancy applications slowing down more patients/users add. i'm sure there way combine these methods (doing exact same thing) 1 method, im not sure how, i'm thinking of creating file array. ideas?

enter image description here

this code regarding 9 imageviews being declared , instantiated

imageview patientone; imageview patienttwo; imageview patientthree;  imageview patientfour;  imageview patientfive;  imageview patientsix;  imageview patientseven;  imageview patienteight;  imageview patientnine;  public void initializeviews() {     patientone=  (imageview)findviewbyid(r.id.patient_one);     patienttwo=  (imageview)findviewbyid(r.id.patient_two);     patientthree=  (imageview)findviewbyid(r.id.patient_three);     patientfour=  (imageview)findviewbyid(r.id.patient_four);     patientfive=  (imageview)findviewbyid(r.id.patient_five);     patientsix=  (imageview)findviewbyid(r.id.patient_six);     patientseven=  (imageview)findviewbyid(r.id.patient_seven);     patienteight=  (imageview)findviewbyid(r.id.patient_eight);     patientnine=  (imageview)findviewbyid(r.id.patient_nine);     newpatient = (button)findviewbyid(r.id.new_patient); }  

these 9 redundant commands pulling patient's/user's images specific corresponding directories

public void getpatientone() {     string path = environment.getexternalstoragedirectory()+ "/perinatalmonitor/patient1/patient.jpg";     file imgfile = new file(path);     if(imgfile.exists())     {         patientone.setimageuri(uri.fromfile(imgfile));     } }  public void getpatienttwo() {     string path = environment.getexternalstoragedirectory()+ "/perinatalmonitor/patient2/patient.jpg";     file imgfile = new file(path);     if(imgfile.exists())     {         patienttwo.setimageuri(uri.fromfile(imgfile));     }    }  public void getpatientthree() {     string path = environment.getexternalstoragedirectory()+ "/perinatalmonitor/patient3/patient.jpg";     file imgfile = new file(path);     if(imgfile.exists())     {         patientthree.setimageuri(uri.fromfile(imgfile));     } }  public void getpatientfour() {     string path = environment.getexternalstoragedirectory()+ "/perinatalmonitor/patient4/patient.jpg";     file imgfile = new file(path);     if(imgfile.exists())     {         patientfour.setimageuri(uri.fromfile(imgfile));     } }  public void getpatientfive() {     string path = environment.getexternalstoragedirectory()+ "/perinatalmonitor/patient5/patient.jpg";     file imgfile = new file(path);     if(imgfile.exists())     {         patientfive.setimageuri(uri.fromfile(imgfile));     } }  public void getpatientsix() {     string path = environment.getexternalstoragedirectory()+ "/perinatalmonitor/patient6/patient.jpg";     file imgfile = new file(path);     if(imgfile.exists())     {         patientsix.setimageuri(uri.fromfile(imgfile));     } } //and on , forth until have 9 patients }//end of class 

these methods called in oncreate method

public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.intro);      initializeviews();       getpatientone();     getpatienttwo();     getpatientthree();     getpatientfour();     getpatientfive();     getpatientsix(); } 

in case currious, how creating patient folders

//  name of folder = patient's number + randomint public void createpatientfolder() {      count=count+1;     stringbuilder sb = new stringbuilder();     sb.append("/perinatalmonitor/patient");     sb.append(count);     testname= sb.tostring();      sharedpreferences pinfo = getsharedpreferences("pf",context.mode_private);     sharedpreferences.editor editor= pinfo.edit();     editor.clear();     editor.putstring("name", testname);     editor.putboolean("safe",false);     editor.commit();      patientfolder = new file(environment.getexternalstoragedirectory() + testname);     boolean success= true;      if(patientfolder.exists()){         toast toast = toast.maketext(this, "already exists", toast.length_long);         toast.show();          createpatientfolder();     }      if(!patientfolder.exists()) {         success = patientfolder.mkdirs();         toast toast = toast.maketext(this, "pass", toast.length_short);         toast.show();     }      if (success) {         toast toast = toast.maketext(this, "pass", toast.length_short);         toast.show();     }      else {         toast toast = toast.maketext(this, "fail", toast.length_short);         toast.show();     } } 

i suggest use imageview array. difference in getpatientxx() methods folder number i.e., patient1, patient2, etc.

it easy have loop iterate through imageviews , set image path.

   public void getpatients() { for(int i=0;i<patient.length;i++) {     string path = environment.getexternalstoragedirectory()+ "/perinatalmonitor/patient"+i+"/patient.jpg";     file imgfile = new file(path);     if(imgfile.exists())     {         patient[i].setimageuri(uri.fromfile(imgfile));     } } } 

where, patient imageview array. method iterate through whole imageview array fetching images folder.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -