Ich habe den folgenden Code ausprobiert.Ordner nicht in der Datei gefunden Browing
public class MainActivity extends GlobalActivity implements CompetitionListAdapter.OnOperationSelectedListener {
private String path = "";
private RecyclerView recyclerView;
private boolean isOnBackPressed = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initLogger("MainActivity");
recyclerView = (RecyclerView) findViewById(R.id.listRecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
//path = "/storage/emulated/0/Download/pictures"; //When I pass this, then I can get the list of files in this folder.
loadFolders(path);
}
private void loadFolders(String path) {
if (this.path.isEmpty()) {
this.path = path;
} else if (!isOnBackPressed) {
this.path += "/" + path; //But when I make same the path dynamically from here file2 is always null.
}
writeLog(this.path);
File f = new File(path);
File file2[] = f.listFiles();
ArrayList<String> folders = new ArrayList<>();
if (file2 != null) {
for (File file1 : file2) {
folders.add(file1.getName());
}
} else {
writeLog("fList is empty");
}
recyclerView.setAdapter(new CompetitionListAdapter(folders, this));
}
@Override
public void onOperationSelected(CompetitionListAdapter.Operation operation, String name) {
isOnBackPressed = false;
loadFolders(name);
}
@Override
public void onBackPressed() {
String paths[] = this.path.split("/");
if (path.length() > 1) {
path = "";
for (int i = 1; i < paths.length - 1; i++) {
path += "/" + paths[i];
}
isOnBackPressed = true;
loadFolders(path);
return;
}
super.onBackPressed();
}
}
So ist der obige Code funktioniert bei der App starten ... Wenn ich einen Ordner aus der Liste wählen, dann mache ich den Weg in loadFolders
dynamisch, aber dieses null immer zurückgibt.
Jede Hilfe wird sehr geschätzt.
wo bist du rufe 'CompetitionListAdapter.OnOperationSelectedListener' in deinem Ada auf Pter? –