我怎么能得到一个FileChooser填充控在TableRow创造?

0

的问题

问题是: 我有麻烦了 FileChooser 类填充 TextView 在一个 TableRow 创造。 我收到一个 Invocation Exception 在创造"looper.java"这似乎会引起一个变量 tagTrace=0 正在读作"!=0". 所以,我不知道我怎么可能能够解决方法。

我想要做的: 我在试图建立在现有进程。 当一个用户点击"+"按钮,在标题行的 TableLayout,它创建了一个行与两个意见:"删除"(-) Button 在排。儿童(0)和一个 TextView 在排。孩子(1)条。 它不会这样成功。 还有一个 Singleton 类,用于管理各种类型的 TableRow 创作于所有的应用程序 Actiities.

在一个特定的 Activity 存在一个文件 TableLayout. 我要用户,当点击"+"buttion我上所述,启动一个 FileChooser 捕捉文件路径和填充,路径 TextView 儿童的行它创建的。 然而,我运行为的问题上。

的Looper.java 错误(I think)造成援引例外

Looper Bug

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

}

该方法内单独建立的TableRow 的"!大胆"

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();

你不能创建一个新的活动 new 操作员。

活动必须开始使用一个意图。

2021-10-21 13:38:09

我看到,我不认为这显然,这是有意义的。
svstackoverflow

其他语言

此页面有其他语言版本

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