Problem: mam problemy z uzyskaniem FileChooser
klasa do wypełnienia TextView
podczas TableRow
tworzenie. Mam Invocation Exception
w utworzonym androida "looper.java" że, podobno, spowodowane zmiennej tagTrace=0
czyta się jak "!=0". Więc nie jestem pewien, jak uda mi się to obejść.
Co staram się zrobić: staram się rozwijać istniejący proces. Gdy użytkownik kliknie na przycisk "+" na pasku tytułu TableLayout
tworzy wiersz z dwoma pojęciami: "Usuń" (-) Button
w wierszu.dziecko(0) i a TextView
w wierszu.dziecko(1). Robi to z powodzeniem. Jest Singleton
klasa, która steruje różnymi rodzajami TableRow
kreacje dla całej aplikacji Actiities
.
Dla jednego konkretnego Activity
istnieje plik TableLayout
. Chcę, aby użytkownik, klikając na przycisk"+", którą opisałem powyżej, uruchomił FileChooser
aby nagrać ścieżkę do pliku i wypełnić w ten sposób w TextView
element podrzędny wiersza, którą on tworzy. Jednak spotykam się z problemem, który jest opisany powyżej.
W Looper.java Błąd (chyba), powodując wyłączenie dzwonka
Udostępnianie plików
public class FileChooser extends AppCompatActivity {
private String fileName;
private String filePath;
private final ActivityResultLauncher<Intent> resultLauncher;
public FileChooser(){
//if(intent==null) Toast.makeText(null, "Intent is Null", Toast.LENGTH_SHORT).show();
this.resultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null){
Uri uri = result.getData().getData();
filePath = uri.getPath();
}
});
}
public String getFileName() {
return fileName;
}
public String getFilePath() {
return filePath;
}
public ActivityResultLauncher<Intent> getResultLauncher() {
return resultLauncher;
}
}
Metoda wewnątrz jednego elementu tworzącego tabelę, pokazuje "!pogrubioną czcionką".
public static TableRow setupFilesTableRow(Context context, TableLayout table, String fileID, String fileName, boolean bold) {
TableRow row = new TableRow(context);
if(bold) {
row.addView(setupFilesAddRowButton(context, table));
row.addView(addRowTextViewToTable(context, fileName, true));
}
if (!bold) {
row.addView(setupDeleteRowButton(context, table));
// Intent and FileChooser to capture a filePath
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
FileChooser fileChooser = new FileChooser();
fileChooser.getResultLauncher().launch(intent);
// Adding a TextView child to the new TableRow with the captured filePath from the FileChooser
row.addView(addRowTextViewToTable(context, fileChooser.getFilePath(), false));
//row.setClickable(true);
}
return row;
}