android - How to go back to parent directory on back button press? -


below code, checks whether selected file directory or file. if directory changes it. how goes parent directory on button press?

i see somehwere in stackflow code goes root.parent when backpress did not found code.

    gridview =(gridview)findviewbyid(r.id.grid);     gridview.setonitemclicklistener(new onitemclicklistener(){     public void onitemclick(adapterview<?> parent, view view, int      position,long id) {       if(currentfiles[position].isdirectory())     {         root = new file("/data/data/com.myexample  /files/"+filename(currentfilepath[position])+"/");          log.e("root first",root+ " ");          currentfiles = root.listfiles();          inflatelistview(currentfiles);     }        private void inflatelistview(file[] files){   list<map<string,object>> listitems = new arraylist<map<string,object>>();   for(int i=0;i<files.length;i++)  {            map<string, object> listitem = new hashmap<string, object>();      if(files[i].isdirectory())     {         listitem.put("icon", r.drawable.folder);     }     else     {         listitem.put("icon", r.drawable.file);     }      listitem.put("filename", files[i].getname());     listitems.add(listitem);   }  simpleadapter=new simpleadapter(this,listitems,r.layout.line,new string[] {"icon","filename"},new int[]{r.id.icon,r.id.file_name}); gridview.setadapter(simpleadapter); 

you need override method called on backpressed:

    /** {@inheritdoc}. */ @override public void onbackpressed() {     if (this.currentdirectory.getparent() != null) {         // --> browse 1 folder up...     } else {         // --> @ root folder     } } 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -