I have a Recylerview
with Button
and TextView
as params. I am opening a file chooser on button click.
@Override
public void onBindViewHolder(final FileChooserAdapter.MyViewHolder holder, final int position) {
PojoClass pojoClass = pojoClassList_.get(position);
holder.listViewName.setText(pojoClass.getListName());
holder.fileBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent filePickIntent = new Intent(Intent.ACTION_GET_CONTENT);
filePickIntent.setType("*/*");
startActivityForResult(filePickIntent, 1);
}
});
}
Now, after selecting the file I am getting the file name in the OnActivityResult
displayName variable. I want to set the holder.textview.setText(displayName);
in onActivityResult
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 1:
// Get the Uri of the selected file
Uri uri = data.getData();
String uriString = uri.toString();
File myFile = new File(uriString);
String path = myFile.getAbsolutePath();
if (uriString.startsWith("content://")) {
Cursor cursor = null;
try {
cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
cursor.close();
}
} else if (uriString.startsWith("file://")) {
displayName = myFile.getName();
}
// I want to place the holder.textview.setText(displayName) here
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
Help me out , how to place the ViewHolder
params to outside of the Adapter
.