Come posso ottenere un File per compilare una TextView durante un TableRow creazione?

0

Domanda

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 TableLayoutcrea 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

Looper Bug

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;
}
android filechooser java tablerow
2021-10-21 13:18:53
1
1

File file = new File();

Non è possibile creare una nuova attività con la new operatore.

Le attività devono essere avviato con un intento.

2021-10-21 13:38:09

Io vedi, io non penso che, ovviamente, ha senso.
svstackoverflow

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................