Problema: sto avendo problemi a trovare un FileChooser
classe popolare un TextView
durante un TableRow
la creazione. Sto ricevendo un Invocation Exception
in Android creato "looper.java" che sembra essere causato da una variabile tagTrace=0
essere letto come "!=0". Quindi, io non sono sicuro di come io possa essere in grado di trovare una soluzione alternativa.
Quello che sto cercando di fare: sto cercando di costruire su di un processo esistente. Quando un utente fa clic su un pulsante "+" sulla riga di intestazione di un TableLayout
crea una riga con due punti di vista: un "Delete" (-) Button
in riga.bambino(0) e un TextView
in riga.bambino(1). Lo fa con successo. C'è un Singleton
classe che gestisce vari tipi di TableRow
creazioni per tutte le app Actiities
.
Su un particolare Activity
esiste un File TableLayout
. Voglio che l'utente, quando si fa clic sul "+" pulsante che ho descritto sopra, per il lancio di un FileChooser
per catturare un percorso di file e compilare il percorso per la TextView
figlio di riga che è la creazione. Tuttavia, sto eseguendo il problema di cui sopra.
Il Looper.java Bug (credo) causando l'invocazione eccezione
Il File
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;
}
}
Il Metodo all'interno di Singleton creazione di TableRow L' "!grassetto"
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;
}