2013-02-12 57 views
1

如何打开和点击Load按钮挑选文件打开SD卡?我想显示一个SD卡的位置,当我点击加载按钮,并从那里选择任何文件,并在主屏幕上显示选定的文件。如何通过按钮点击显示在主菜单中选择文件

谁能帮助我如何在屏幕上显示从SD卡显示选定的文件?

Button loadButton = (Button) findViewById(R.id.loadButton); 
loadButton.setOnClickListener(new OnClickListener() { 
    public void onClick(View v) { 

    } 
}); 
+0

要显示所选文件的路径? – 2013-02-12 12:30:01

+0

你见过吗? – Stan 2013-02-12 12:40:37

回答

0

您需要启动活动添加在Manifasto.xml以下代码文件

<activity 
      android:name=".fileDialog" 
      android:configChanges="orientation" 
      android:screenOrientation="reverseLandscape" /> 
在Java

您需要添加方法

public void onButtonClick(View v) { 
     pathSelect = "/sdcard/"; 
     Intent myIntent = new Intent(getBaseContext(), 
       fileDialog.class); 
     myIntent.putExtra(fileDialog.START_PATH, 
       pathSelect); 
    startActivityForResult(pathSelect, REQUEST_SAVE);  
    } 

public synchronized void onActivityResult(final int requestCode, 
      int resultCode, final Intent data) { 
     String filename = "null"; 
     if (resultCode == Activity.RESULT_OK) { 
      filename = data.getStringExtra(FileDialog.RESULT_PATH);   
     } else if (resultCode == Activity.RESULT_CANCELED) { 
// do on cancle button click 
          } 
} 
相关问题