Old school Swatch Watches
logo

Chatbox|Admin nhận làm wap/web, giá cả thương lượng... Thông tin admin tại mỗi bài viết.
Home · Bang hội ·
* Đăng Nhập hoặc Đăng Kí
để sử dụng hết chức năng của diễn đàn.
Hi, Khách!
HomeBang hội » Thủ thuật » Nokia s40 » » Xem bài viết
Xuống dưới »
avatar by Pham_loi Pham_loi
Chức vụ:
15:47:13, 26-05-2016

FileBrowser - Duyệt file trên nền list

. code đơn giản nên thôi giải thích.
<?php
import javax
.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;

public class 
FileBrowser extends javax.microedition.lcdui.List implements CommandListener {
//Đường dẫn hiện tại
String path="/";
//tạo 2 commmand để nhấn
Command ok=new Command("Ok",Command.OK,1);
Command cancel=new Command("Hủy",Command.CANCEL,2);

     public 
FileBrowser() {
         
super("FileBrowser"javax.microedition.lcdui.List.IMPLICIT);
         
addCommand(ok);
         
addCommand(cancel);
         
setSelectCommand(ok);
         
setCommandListener(this);
         
open();
     }
     
     public 
void commandAction(Command c,Displayable dab){
         if(
c==ok){
             
int select=getSelectedIndex();
             
String t=getString(select);
             if(
path.length()>1){
                 if(
select==0){
                     
//về thư mục trước
                     
path=subpath(path);
                     
refresh();
                 }
                 else {
                     if(
t.endsWith("/")){
                         
path+=t;
                         
refresh();
                     }else{
                         
//file
                     
}
                 }
             }else {
                 
path+=t;
                 
refresh();
             }
         }else if(
c==cancel){
             
//exit chẳng hạn
         
}
     }
     
     public 
void open(){
         
path="/";
         
refresh();
     }
     
     public 
void refresh(){
         try{
             
//xóa tất cả
             
deleteAll();
             
Enumeration mEnum;
             if(
path.length()>1){
                 
FileConnection fc=(FileConnection)Connector.open("file://"+path,1);
                 
mEnum=fc.list();
                 
append(new String("..."),null);
             }
             else 
mEnum=FileSystemRegistry.listRoots();
             while(
mEnum.hasMoreElements())
                 
append((String)mEnum.nextElement(),null);
         }catch(
Exception e){
             if(
path.length()>1){
                 
//lấy lại đường dẫn trước
                 
path=subpath(path);
                 
refresh();
             }else {
                 
open();
             }
         }
     }

     public 
void setPath(String path){
         
this.path=path;
         
refresh();
     }

     public 
String getPath(){
         return 
path;
     }

     public 
String subpath(String p){
         return 
p.substring(0p.substring(0p.length()-1).lastIndexOf('/')+1);
     }
}
?>

Copy code

Like: 0

Trực Tuyến: Khách: 1
Diễn đàn teen Việt Nam
CopyRight 2014