ยังไงฉัน FileChooser จะ populate เป็น TextView ตอน TableRow การสร้าง?

0

คำถาม

ปัญหา: ฉันมีปัญหาได้ FileChooser ชั้นเรียนต้องไป populate น TextView ระหว่าง TableRow สิ่งที่พระเจ้าสร้าง ฉันได้รับเป็น Invocation Exception ใน Android กสร้างขึ้น"looper.java"ซึ่งดูเหมือนจะเกิดจากตัวแปร tagTrace=0 ถูกอ่านเป็น"!=0". ดังนั้นฉันไม่แน่ใจว่าฉันอาจจะสามารถ workaround มัน

สิ่งที่ฉันกำลังพยายามทำ: ฉันกำลังพยายามสร้างขึ้นเพื่อที่มีอยู่แล้วการประมวลผล ตอนที่เป็นของผู้ใช้ลิน"+"เพื่ออยู่ส่วนหัวแถวของ TableLayoutมันสร้างแถวกับสองมุมมอง:a"ลบ"(-) Button ในแถวด้วยเด็กคน(0)และ TextView ในแถวด้วยเด็ก(1). มันทำอย่างนี้เรียบร้อยแล้ว มันเป็น Singleton ชั้นเรียนนั่นพาะระเภทต่างๆของ TableRow creations สำหรับแอ๊ป Actiities.

บนหนึ่งโดยเฉพาะ Activity อยู่ก่อนเป็นแฟ้ม TableLayout. ฉันต้องการผู้ใช้เมื่อมีการคลิกที่"+"buttion ฉันถูกระบุไว้ด้านบนเพื่อเรียกใช้เป็น FileChooser ต้องถูกจับเป็นแฟ้มเส้นทางและ populate ทางเส้นนั้นไป TextView ลูกของแถวมันคือการสร้าง. อย่างไรก็ตามผมวิ่งเข้าหาปัญหาด้านบน

คน Looper.java แมล(ฉันคิดว่า)เนื่องจาก invocation นข้อยกเว้น

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

}

จากวิธีการภายใน Singleton กำลังสร้างค 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=ใหม่ FileChooser();

คุณไม่สามารถสร้างใหม่กับกิจกรรม new โอเปอเรเตอร์ค่ะ

กิจกรรมต้องเริ่มโดยใช้การตั้งใจ.

2021-10-21 13:38:09

ฉันเห็นฉันไม่คิดอย่างนั้นหรอกเห็นได้ชัดว่ามันสมเหตุสมผลเลย
svstackoverflow

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

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