Cum pot obține un FileChooser pentru a popula un TextView în timpul unei TableRow creație?

0

Problema

Problema: am probleme cu obtinerea un FileChooser clasa a popula un TextView în timpul unei TableRow crearea. Am primit o Invocation Exception în Android creat "looper.java" ceea ce pare a fi cauzată de o variabilă tagTrace=0 a fi citit ca "!=0". Deci, eu nu sunt sigur cum am putea fi în măsură pentru a rezolva problema asta.

Ceea ce încerc să fac: eu sunt încercarea de a construi pe un proces existent. Atunci când un utilizator face clic pe un buton "+" de pe rândul antet al unui TableLayoutse creează un rând, cu două puncte de vedere: un "Delete" (-) Button în rând.copil(0) și o TextView în rând.copil(1). Ea face acest lucru cu succes. Există o Singleton clasa care gestionează diverse tipuri de TableRow creatii pentru toate app Actiities.

Pe un anumit Activity există un Fișiere TableLayout. Vreau utilizator, atunci când faceți clic pe "+" buttion am descris mai sus, pentru a lansa o FileChooser pentru a captura o cale de fișier și popula această cale la TextView copilul de rând este crearea. Cu toate acestea, eu sunt difuzate în problema de mai sus.

La Looper.java Bug (cred) provoacă invocarea excepție

Looper Bug

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

}

Metoda în Singleton crearea TableRow A "!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;
}
android filechooser java tablerow
2021-10-21 13:18:53
1
1

FileChooser fileChooser = new FileChooser();

Nu puteți crea o nouă activitate cu new operator.

Activitățile trebuie să fi pornit folosind o intentie.

2021-10-21 13:38:09

Am văzut, nu m-am gândit că, evident, are sens.
svstackoverflow

În alte limbi

Această pagină este în alte limbi

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