How can i create 2 directory lists in the same layout? One to show file and folder from FTP server and the other to show local file/folder.
Edit: I can put arrayadapter to Listview now with this line: listView.setAdapter(adapter); So I think I can create more directory list in the same layout. But when I run the app, click on folder, no effect. Here is all my code.
public class FileChooser extends ListActivity {
private File currentDir;
private FileArrayAdapter adapter;
private TextView myPath;
ListView listViewLocal;
ListView listFtp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myPath = (TextView)findViewById(R.id.path);
listViewLocal = (ListView) findViewById(R.id.listlocal);
//listFtp = (ListView) findViewById(R.id.);
currentDir = new File("/sdcard/");
fill(currentDir);
}
private void fill(File f)
{
File[]dirs = f.listFiles();
//this.setTitle("Current Dir: "+f.getName());
myPath.setText("Location: " + f.getName());
List<Option>dir = new ArrayList<Option>();
List<Option>fls = new ArrayList<Option>();
try{
for(File ff: dirs)
{
if(ff.isDirectory())
dir.add(new Option(ff.getName(),"Folder",ff.getAbsolutePath()));
else
{
fls.add(new Option(ff.getName(),"File Size: "+ff.length(),ff.getAbsolutePath()));
}
}
}catch(Exception e)
{
}
Collections.sort(dir);
Collections.sort(fls);
dir.addAll(fls);
if(!f.getName().equalsIgnoreCase("sdcard"))
dir.add(0,new Option("..","Parent Directory",f.getParent()));
adapter = new FileArrayAdapter(FileChooser.this,R.layout.file_view,dir);
listViewLocal.setAdapter(adapter);
//this.setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Option o = adapter.getItem(position);
if(o.getData().equalsIgnoreCase("folder")||o.getData().equalsIgnoreCase("parent directory")){
currentDir = new File(o.getPath());
fill(currentDir);
}
else
{
onFileClick(o);
}
}
private void onFileClick(Option o)
{
Toast.makeText(this, "File Clicked: "+o.getName(), Toast.LENGTH_SHORT).show();
}
}
Thanks in advance,