0

我正在编写一个应用程序,它允许用户输入 URL,然后选择放置下载文件的位置。但我被困在第二步。我想要做的就是显示这样的位置: 在此处输入图像描述

并返回位置的路径。有人有解决方案吗?提前致谢!PS:显示外部存储。

4

2 回答 2

0

Create activity

    public class ... extend activity
    {

    string path  = "/";

    public void onResume()
    {
     ...
     setContentView(..);
     if (getIntent().hasExtra("path"))
     {
       path = getIntent().getStringExtra("path");
     }

     listview = findviewbyid(R.id.listview);

     listview.setAdapter(new adapter(path));

     listview.setOnItemClickListener(this);
    }

    public void onActivityResult(result)
    {
      if (resultOK) ...
    }

    public void onclicklisteneer(view,pos,id)
    {
     if (dir)
     {
      Intent intent = new Intent(this, this.class);
      intent.put("path",path+" "+view.getAdapter().getItem(pos))
      intent.setFlag(FLAG_NEW_TASK)
      startActivityForResult(intent)
     } 
     else if (file)
     {
      setResult(Result_OK);
      finish();
     }

    }

   }
于 2013-01-24T09:34:20.213 回答
0

我就是这样做的,它对我有用:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tree_view);

    File dir = new File("/sdcard");
    ArrayList<String> folders = new ArrayList<String>();
    final File[] fileList = dir.listFiles();

    if (fileList == null){
        Toast msg = Toast.makeText(this, "No files", 3000);
        msg.show();
    }else{
        for (File f:fileList){
            if (f.isDirectory()){
                folders.add(f.getName());
            }
        }
        final ListView lvFolder = (ListView)findViewById(R.id.lvTree);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_selectable_list_item, folders);
        lvFolder.setAdapter(adapter);
        lvFolder.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View v,
                    int position, long id) {
                // TODO Auto-generated method stub
                Object o = lvFolder.getItemAtPosition(position);
              String fullObject = (String)o;
              Toast.makeText(getApplicationContext(), "You have chosen: " + " " + fullObject.toString(), Toast.LENGTH_LONG).show();
            }
        });
    }

}
于 2013-01-24T10:29:08.353 回答