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