如何通过点击加载按钮打开并选择文件?当我点击加载按钮并从那里选择任何文件并在主屏幕上显示所选文件时,我想显示SD卡位置。
有人可以帮我解决如何在屏幕上显示SD卡显示的选定文件吗?
Button loadButton = (Button) findViewById(R.id.loadButton);
loadButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
}
});
答案 0 :(得分: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
}
}