Problém: mám problémy s získanie FileChooser
trieda k naplneniu TextView
počas TableRow
vytvorenie. Som príjem Invocation Exception
v Android vytvorený "looper.java" čo sa zdá byť spôsobené premennej tagTrace=0
čítať ako "!=0". Takže si nie som istý, ako I možné riešenie je.
To, čo sa snažím robiť: snažím sa stavať na existujúcej procesu. Keď používateľ klikne na "+" tlačidlo na hlavička riadok TableLayout
to vytvára riadok s dva názory: "Delete" (-) Button
v riadku.dieťa(0) a TextView
v riadku.dieťa(1). To robí to úspešne. Tam je Singleton
triedy, ktoré spravuje rozličné typy TableRow
výtvory pre všetky aplikácie Actiities
.
Na jeden konkrétny Activity
existuje Súbory TableLayout
. Chcem užívateľov, kliknutím na "+" buttion som opísal vyššie, začať FileChooser
zachytiť cestu k súboru a naplniť, že cesta k TextView
dieťa riadku je vytvorenie. Avšak, som sa beží do problematiky vyššie.
Na Looper.java Bug (myslím, že) spôsobuje aktivácia výnimkou
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;
}
}
Metóda, v rámci Singleton vytvorenie TableRow Na "!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;
}