我正在使用文件管理器应用程序。正如我们通常看到的那样,在 Android 中打开默认文件管理器会显示主存储路径,由正向箭头“>”分隔。
现在的问题是,当我运行下面的应用程序代码时,路径显示如下 - “/storage/emulated/0/Music/testZip” 而我需要“storage > emulated> Main > Music > testZip” 这种类型的路径拆分和可点击,如中所示->此处的示例
以下是代码部分。运行时权限代码块也被忽略。
public class MainActivity extends AppCompatActivity {
ListMainAdapter listMainAdapter;
TextView storagePathSplitWithArrow;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
storagePathSplitWithArrow = findViewById(R.id.storageMainPath);
mListView = findViewById(R.id.list1);
File StrPath11 = Environment.getExternalStorageDirectory();
storagePathSplitWithArrow.setText(StrPath1.getPath().toString());
File pathMainDirectory = new File(StrPath11.getPath());
final File[] path = pathMainDirectory.listFiles();
for (File file : path) {
if (file.isDirectory()) {
pathDirectries.add(file.getName());
} else {
pathFiles.add(file);
}
}
listAdapterMain = new ListAdapterMain(MainActivity.this, pathDirectries);
mListView.setAdapter(listAdapterMain);
File nameGLobal = new File(pathMainDirectory );
String globalPath = nameGLobal.getName();
SpannableStringBuilder ssb = new
SpannableStringBuilder(pathToFileStr);
ssb.append(globalPath);
ssb.setSpan(new ImageSpan(MainActivity.this,
R.drawable.ic_arrow_path), ssb.length(), ssb.length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
ssb.append(globalPath);
storagePathSplitWithArrow.setText(ssb, TextView.BufferType.NORMAL);
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/storageMainPath"
android:layout_width="match_aprent"
android:layout_height="wrap_content"
android:text="@+id/label"
>
</TextView>
<ListView
android:id="@+id/list1"
android:divider="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/storageMainPath"/>
</RelativeLayout>
结果是这样的 - 结果主列表视图数据是
还例如,somoneone 在此路径中单击“音乐”,然后加载的列表视图数据将是“音乐”目录中的存储数据,依此类推,如上图示例中所述。