Problém: mám potíže dostat FileChooser
třídy naplnit TextView
během TableRow
vytvoření. Já obdržení Invocation Exception
v Android "looper.java" což se zdá být způsobeno proměnnou tagTrace=0
čte jako "!=0". Takže, nejsem si jistý, jak jsem může být schopen řešení.
To, co se snažím dělat: snažím se stavět na existující proces. Když uživatel klikne na tlačítko "+" v záhlaví řádek TableLayout
to vytváří řadu s dvěma názory: "Smazat" (-) Button
v řádku.dítě(0) a TextView
v řádku.dítě(1). To dělá to úspěšně. Tam je Singleton
třídy, které spravuje různé typy TableRow
výtvory pro všechny aplikace Actiities
.
Na jeden konkrétní Activity
existuje Souborů TableLayout
. Chci uživatele, po kliknutí na "+" buttion jsem popsal výše, k zahájení FileChooser
zachytit cestu k souboru a naplnění, že cesta k TextView
dítě řádku je vytváří. Nicméně, jsem běh do problematiky výše.
Na Looper.java Chyba (myslím), což způsobuje vyvolání výjimky
Na FileChooser
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;
}
}
Metody ve Singleton vytváření TableRow "!bold"
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;
}