Como posso obter uma correção da para preencher um TextView durante um TableRow criação?

0

Pergunta

Problema: estou tendo problemas para conseguir um FileChooser classe para preencher uma TextView durante uma TableRow criação. Eu recebendo um Invocation Exception no Android criado "looper.java" o que parece ser causado por uma variável tagTrace=0 está a ser lido como "!=0". Então, eu não tenho certeza de como eu possa ser capaz de solução alternativa.

O que eu estou tentando fazer: eu estou tentando construir um processo existente. Quando um usuário clica em um botão "+" na linha de cabeçalho de um TableLayout, ele cria uma linha com dois pontos de vista: um "Delete" (-) Button na linha.criança(0) e um TextView na linha.criança(1). Ele faz isso com êxito. Há um Singleton classe que gerencia diversos tipos de TableRow criações para que todos os app Actiities.

Em um determinado Activity existe uma Ficheiros TableLayout. Eu quero que o usuário, ao clicar no "+" buttion eu descrevi acima, para o lançamento de um FileChooser para capturar um caminho de arquivo e preencha o caminho para o TextView filho da linha que está a criar. No entanto, eu estou correndo para o problema acima.

O Looper.java Bug (eu acho) fazendo com que a invocação da excepção

Looper Bug

A Correção Da

    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;
        }

}

O Método dentro da Singleton criar o TableRow O "!negrito"

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

Correção da correção da = new correção da();

Você não pode criar uma nova atividade com o new o operador.

Actividades têm de ser iniciado através de uma intenção.

2021-10-21 13:38:09

Eu vejo, eu não acho que, obviamente, que fazem sentido.
svstackoverflow

Em outros idiomas

Esta página está em outros idiomas

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