android - how to convert an class extends activity into independent class -


i have class extending activity , have methods oncreate(),onbackpress() etc. want turn independent class above methods become undefined. problem? shouldn't importing classes enough? eg, import android.view.view findviewbyid still makes no difference. please advise.

file_explore

 public class file_explorer extends activity {          // stores names of traversed directories         arraylist<string> str = new arraylist<string>();          // check if first level of directory structure 1 showing         private boolean firstlvl = true;          string adatarow = "";            static stringbuilder abuffer = new stringbuilder();          string abuffer1="";         private static final string tag = "f_path";         static long filesizeinmb;         private item[] filelist;         private file path = new file(environment.getexternalstoragedirectory().getabsolutepath());         private string chosenfile;         private static final int dialog_load_file = 0;         static string fileextension="";         listadapter adapter;          @override         public void oncreate(bundle savedinstancestate) {              super.oncreate(savedinstancestate);              loadfilelist();              showdialog(dialog_load_file);             log.d(tag, path.getabsolutepath());          }          private void loadfilelist() {             try {                 path.mkdirs();             } catch (securityexception e) {                 log.e(tag, "unable write on sd card ");             }              // checks whether path exists             if (path.exists()) {                 filenamefilter filter = new filenamefilter() {                     @override                     public boolean accept(file dir, string filename) {                         file sel = new file(dir, filename);                         // filters based on whether file hidden or not                         return (sel.isfile() || sel.isdirectory())                                 && !sel.ishidden();                      }                 };                  string[] flist = path.list(filter);                 filelist = new item[flist.length];                 (int = 0; < flist.length; i++) {                     filelist[i] = new item(flist[i], r.drawable.ic_launcher);                      // convert file path                     file sel = new file(path, flist[i]);                      // set drawables                     if (sel.isdirectory()) {                         filelist[i].icon = r.drawable.ic_launcher;                         log.d("directory", filelist[i].file);                     } else {                         log.d("file", filelist[i].file);                     }                 }                  if (!firstlvl) {                     item temp[] = new item[filelist.length + 1];                     (int = 0; < filelist.length; i++) {                         temp[i + 1] = filelist[i];                     }                     temp[0] = new item("back", r.drawable.ic_launcher);                     filelist = temp;                 }             } else {                 log.e(tag, "path not exist");             }              adapter = new arrayadapter<item>(this,                     android.r.layout.select_dialog_item, android.r.id.text1,                     filelist) {                 @override                 public view getview(int position, view convertview, viewgroup parent) {                     // creates view                     view view = super.getview(position, convertview, parent);                     textview textview = (textview) view                             .findviewbyid(android.r.id.text1);                      // put image on text view                     textview.setcompounddrawablepadding(                             filelist[position].icon);                        return view;                 }             };          }          private class item {             public string file;             public int icon;              public item(string file, integer icon) {                 this.file = file;                 this.icon = icon;             }              @override             public string tostring() {                 return file;             }         }          @override         protected dialog oncreatedialog(int id) {             dialog dialog = null;             alertdialog.builder builder = new builder(this);              if (filelist == null) {                 log.e(tag, "no files loaded");                 dialog = builder.create();                 return dialog;             }              switch (id) {             case dialog_load_file:                 builder.settitle("choose file");                 builder.setadapter(adapter, new dialoginterface.onclicklistener() {                     @override                     public void onclick(dialoginterface dialog, int which) {                         chosenfile = filelist[which].file;                         file sel = new file(path + "/" + chosenfile);                         if (sel.isdirectory()) {                             firstlvl = false;                              // adds chosen directory list                             str.add(chosenfile);                             filelist = null;                             path = new file(sel + "");                              loadfilelist();                              removedialog(dialog_load_file);                             showdialog(dialog_load_file);                             log.d(tag, path.getabsolutepath());                           }                          // checks if 'up' clicked                         else if (chosenfile.equalsignorecase("back") && !sel.exists()) {                              // present directory removed list                              string s = str.remove(str.size() - 1);                              // path modified exclude present directory                             path = new file(path.tostring().substring(0,                                     path.tostring().lastindexof(s)));                             filelist = null;                              // if there no more directories in list,                             // first level                             if (str.isempty()) {                                 firstlvl = true;                             }                             loadfilelist();                              removedialog(dialog_load_file);                             showdialog(dialog_load_file);                             log.d(tag, path.getabsolutepath());                          }                         // file picked                         else {                             // perform action file picked                              fileextension                               = mimetypemap.getfileextensionfromurl(sel.tostring());                             // toast.maketext(getapplication(), fileextension, toast.length_long).show();                              long filesizeinbytes = sel.length();                              filesizeinmb = filesizeinbytes/(1024*1024);                              toast.maketext(getapplication(), string.valueof(filesizeinmb).tostring(), toast.length_long).show();                              if(filesizeinmb >1){                                   intent returnintent = new intent();                                     returnintent.putextra("name", abuffer.tostring());                                     setresult(result_ok, returnintent);                                 }                              else{                                  try{                                 //  arraylist<string> myfiles = new arraylist<string>();                                fileinputstream fin = new fileinputstream(sel);                                   bufferedreader myreader = new bufferedreader(                                           new inputstreamreader(fin));                                    while ((adatarow = myreader.readline()) != null) {                                       abuffer.append(adatarow.tostring()).append("\n");                                   }                                // abuffer1 = abuffer.tostring();                                 myreader.close();                                       }catch (filenotfoundexception e)                              {e.printstacktrace();}                               catch (ioexception e) {                                   e.printstacktrace();                               }                            // toast.maketext(getapplicationcontext(),abuffer,toast.length_long).show();                               intent returnintent = new intent();                             returnintent.putextra("name", abuffer.tostring());                             setresult(result_ok, returnintent);                              finish();                          }                                }                          abuffer.delete(0, abuffer.length());                     //  abuffer1=null;                           }                      }                 );                 break;             }             dialog = builder.show();             return dialog;           }          @override         public void onbackpressed() {             // todo auto-generated method stub             super.onbackpressed();             intent i= new intent(this, file_selecter.class);               startactivity(i);         }       } 


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -