Ako môžem získať FileChooser k naplneniu TextView počas TableRow stvorenia?

0

Otázka

Problém: mám problémy s získanie FileChooser trieda k naplneniu TextView počas TableRow vytvorenie. Som príjem Invocation Exception v Android vytvorený "looper.java" čo sa zdá byť spôsobené premennej tagTrace=0 čítať ako "!=0". Takže si nie som istý, ako I možné riešenie je.

To, čo sa snažím robiť: snažím sa stavať na existujúcej procesu. Keď používateľ klikne na "+" tlačidlo na hlavička riadok TableLayoutto vytvára riadok s dva názory: "Delete" (-) Button v riadku.dieťa(0) a TextView v riadku.dieťa(1). To robí to úspešne. Tam je Singleton triedy, ktoré spravuje rozličné typy TableRow výtvory pre všetky aplikácie Actiities.

Na jeden konkrétny Activity existuje Súbory TableLayout. Chcem užívateľov, kliknutím na "+" buttion som opísal vyššie, začať FileChooser zachytiť cestu k súboru a naplniť, že cesta k TextView dieťa riadku je vytvorenie. Avšak, som sa beží do problematiky vyššie.

Na Looper.java Bug (myslím, že) spôsobuje aktivácia výnimkou

Looper Bug

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

}

Metóda, v rámci Singleton vytvorenie TableRow Na "!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();

Nie je možné vytvoriť novú aktivitu s new prevádzkovateľ.

Aktivity musia začať používať zámer.

2021-10-21 13:38:09

Vidím, nemyslela som si, že je zrejmé, že zmysel.
svstackoverflow

V iných jazykoch

Táto stránka je v iných jazykoch

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