Problema: estoy teniendo problemas para conseguir una FileChooser
clase para llenar un TextView
durante un TableRow
la creación. He recibido un Invocation Exception
en el Android creado "looper.java" lo que parece ser causada por una variable tagTrace=0
que se lea como "!=0". Así que, no estoy seguro de lo que puede ser capaz de la solución.
Lo que estoy tratando de hacer: estoy tratando de construir en un proceso existente. Cuando un usuario hace clic en un botón "+" en la fila de encabezado de un TableLayout
, crea una fila con dos vistas: una "Eliminar" (-) Button
en la fila.niño(0) y un TextView
en la fila.niño(1). Esto se hace correctamente. Hay un Singleton
clase que gestiona distintos tipos de TableRow
creaciones para todas las aplicaciones Actiities
.
En una en particular Activity
existe un Archivos TableLayout
. Quiero que el usuario, al hacer clic en el "+" buttion he descrito anteriormente, el lanzamiento de un FileChooser
para capturar una ruta de acceso de archivo y llenar la ruta de acceso a la TextView
niño de la fila que está creando. Sin embargo, me estoy quedando en la cuestión anterior.
El Looper.java Bug (creo) de la causa de la invocación de la excepción
El 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;
}
}
El Método en el Singleton de la creación de la TableRow El "!negrita"
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;
}