Попробуйте этот код, не нужно снова ссылаться на tvDocName в выбранном файле, просто измените этот код в выбранном файле
public class DocumentActivity extends AppCompatActivity {
ImageView toolbar_back;
TextView next;
RecyclerView recyclerView;
ArrayList<Survey_vehiclepojo> mylist = new ArrayList();
My_document_adapter adapter;
TextView tvDocName;
View view;
private int position;
String displayName = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_document);
view = getLayoutInflater().inflate(R.layout.activity_document, null);
tvDocName = findViewById(R.id.tvDocName);
// toolbar_back=(ImageView)findViewById(R.id.toolbar_back);
// toolbar_back.setOnClickListener(this);
// next=(TextView)findViewById(R.id.next);
// next.setOnClickListener(this);
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
mylist.add(new Survey_vehiclepojo("Pay Slip"));
mylist.add(new Survey_vehiclepojo("Insurance"));
mylist.add(new Survey_vehiclepojo("NA Certificate"));
adapter = new My_document_adapter(DocumentActivity.this, mylist);
recyclerView.setAdapter(adapter);
}
/* @Override
public void onClick(View v) {
switch (v.getId()){
*//*case R.id.toolbar_back:
finish();
break;
case R.id.next:
Intent n=new Intent(DocumentActivity.this,Loan_checklistActivity.class);
startActivity(n);
break;*//*
}
}*/
public void Document(int pos) {
position = pos;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, 100);
tvDocName.setText(mylist.get(pos).getPay_slip());
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
selectedFile(data);
}
private void selectedFile(Intent data) {
if (data != null) {
Uri uri = data.getData();
String uriString = null;
if (uri != null) {
uriString = uri.toString();
}
File myFile = new File(uriString);
String path = myFile.getAbsolutePath();
if (uriString != null) {
if (uriString.startsWith("content://")) {
try (Cursor cursor = DocumentActivity.this.getContentResolver().query(uri, null, null, null, null)) {
if (cursor != null && cursor.moveToFirst()) {
displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
Toast.makeText(this, "display" + displayName, Toast.LENGTH_SHORT).show();
// Toast.makeText(this, "path is" +path, Toast.LENGTH_SHORT).show();
// My_document_adapter.Filename(displayName, position);
// ViewGroup v = (ViewGroup) getLayoutInflater().inflate(R.layout.activity_document, null);
// tvDocName = v.findViewById(R.id.tvDocName);
tvDocName.setText(displayName);
adapter.notifyDataSetChanged();
}
}
}
} else if (uriString.startsWith("file://")) {
displayName = myFile.getName();
Toast.makeText(this, "display start " + displayName, Toast.LENGTH_SHORT).show();
// ViewGroup v = (ViewGroup) getLayoutInflater().inflate(R.layout.activity_document, null);
// tvDocName = v.findViewById(R.id.tvDocName);
tvDocName.setText(displayName);
adapter.notifyDataSetChanged();
}
}
}
}