I am trying to get the the filepath of a file from file manager and display the filepath in a text view. I am able to open the file manager however when i set text i get a java.lang.IllegalStateException: textview must not be null
Here is the code that opens the File manager from a dialog
private fun openCSVUploadDialog(){
val uploadCsv = Dialog(requireActivity(), R.style.FullScreenDialogStyle)
uploadCsv.requestWindowFeature(Window.FEATURE_NO_TITLE)
uploadCsv.setContentView(R.layout.csv_upload_dialog)
uploadCsv.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
uploadCsv.show()
uploadCsv.tvUpload.setOnClickListener {
val intent = Intent(Intent.ACTION_GET_CONTENT)
.setType("*/*")
startActivityForResult(intent,UPLOAD_FILE_CODE)
}
uploadCsv.btnUpload.setOnClickListener {
uploadCsv.dismiss()
}
}
Where i am the file path to the set text
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when(requestCode){
UPLOAD_FILE_CODE -> {
if (resultCode == RESULT_OK){
val path = data!!.data!!.path
csvFilePath.text = path
}
}
}
}
csvFilePath is my text view
Where is this code written?? fragment or activity or some utility class??
If fragment, initialize the csvFilePath with findViewById in onCreateView
if activity , do the same in OnCreate
if some other class, Post the result to activity and update UI
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.