I have a class (DisplayIMageFromFTP_3) which extends RecyclerViewer Class (MyRecyclerViewAdapater)
public class DisplayImageFromFTP_3 extends AppCompatActivity implements MyRecyclerViewAdapter_3.ItemClickListener
How I populate the adapater
private void callRecyclerAdapter() {
adapter = new MyRecyclerViewAdapter_3(this,
arrayListString_url_abs_fileName,
arrayListString_url_fileName,
arrayListString_url_fileExtension,
arrayListString_url_fileDate,
arrayListString_url_fileSize);
adapter.setClickListener(this);
recyclerView.setAdapter(adapter);
}
MyRecyclerViewAdapter_3:
class MyRecyclerViewAdapter_3 extends RecyclerView.Adapter<MyRecyclerViewAdapter_3.ViewHolder> {
private ArrayList<String> arrayListString_url_abs_fileName,
arrayListString_url_fileName,
arrayListString_url_fileExtension,
arrayListString_url_fileDate,
arrayListString_url_fileSize;
String url_abs_fileName,
url_fileName,
url_fileExtension,
url_fileDate,
url_fileSize;
private LayoutInflater mInflater;
private ItemClickListener mClickListener;
PopupWindow popupWindow;
private Context pContext, aContext; //Context for Popup Window (got from onCreateViewHolder)
// data is passed into the constructor
MyRecyclerViewAdapter_3(Context context,
ArrayList<String> url_abs_fileName,
ArrayList<String> url_fileName,
ArrayList<String> url_fileExtension,
ArrayList<String> url_fileDate,
ArrayList<String> url_fileSize) {
this.mInflater = LayoutInflater.from(context);
this.arrayListString_url_abs_fileName = url_abs_fileName;
this.arrayListString_url_fileName = url_fileName;
this.arrayListString_url_fileExtension = url_fileExtension;
this.arrayListString_url_fileDate = url_fileDate;
this.arrayListString_url_fileSize = url_fileSize;
}
// inflates the row layout from xml when needed
@Override
@NonNull
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = mInflater.inflate(R.layout.recyclerview_item, parent, false);
pContext = parent.getContext();
return new ViewHolder(view);
}
// binds the data to the view
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
url_abs_fileName = arrayListString_url_abs_fileName.get(position);
url_fileName = arrayListString_url_fileName.get(position);
url_fileExtension = arrayListString_url_fileExtension.get(position);
url_fileDate = arrayListString_url_fileDate.get(position);
url_fileSize = arrayListString_url_fileSize.get(position);
Context mContext = holder.ivHorizontalGrid.getContext();
Glide.with(mContext)
.load(url_abs_fileName)
.thumbnail(0.05f)
//.diskCacheStrategy(DiskCacheStrategy.DATA)
.placeholder(R.drawable.loading)
.error(R.drawable.error).
into(holder.ivHorizontalGrid)
;
holder.ibDots.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view_item) {
url_abs_fileName = arrayListString_url_abs_fileName.get(position);
url_fileName = arrayListString_url_fileName.get(position);
url_fileExtension = arrayListString_url_fileExtension.get(position);
url_fileDate = arrayListString_url_fileDate.get(position);
url_fileSize = arrayListString_url_fileSize.get(position);
setupPopUpWindow(view_item);
}
});
}
// total number of rows
@Override
public int getItemCount() {
return arrayListString_url_abs_fileName.size();
}
// stores and recycles views as they are scrolled off screen
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView ivHorizontalGrid;
ImageButton ibDots;
ViewHolder(View itemView) {
super(itemView);
ivHorizontalGrid = itemView.findViewById(R.id.ivHorizontalGrid);
ibDots = itemView.findViewById(R.id.ibDots);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (mClickListener != null) mClickListener.onItemClick(view, getAdapterPosition());
//Log.d("LOG", "zzz_Click: " +view);
}
}
// convenience method for getting data at click position
public String getItem(int id) {
return arrayListString_url_abs_fileName.get(id);
}
// allows clicks events to be caught
public void setClickListener(ItemClickListener itemClickListener) {
this.mClickListener = itemClickListener;
}
// parent activity will implement this method to respond to click events
public interface ItemClickListener {
void onItemClick(View view, int position);
}
//Popup Window
private void setupPopUpWindow(View view_item) {
LayoutInflater inflater = (LayoutInflater) pContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view_layout;
view_layout = inflater.inflate(R.layout.dots_menu_layout, null);
popupWindow = new PopupWindow(view_layout,560, 740, true);
popupWindow.showAsDropDown(view_item,-153,0);
//Display FileName
TextView tvFileName = view_layout.findViewById(R.id.tvFileName);
tvFileName.setText(url_fileName);
tvFileName.setSelected(true); //android:ellipsize="marquee"
//Display Sub Text (Extension . Date . Size)
TextView tvSub = view_layout.findViewById(R.id.tvSub);
tvSub.setText(url_fileExtension.toUpperCase() +" \u2022 "+url_fileDate +" \u2022 " +url_fileSize);
//MENU ~ SHARE
LinearLayout ll_share;
ll_share = view_layout.findViewById(R.id.ll_share);
ll_share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
downloadFileForShare();
}
private void downloadFileForShare() {
new DisplayImageFromFTP_3.Async_GetImageFromFTP(this).execute();
}
});
}
}
Now I'm trying to call an Async task from DisplayImageFromFTP_3 class like this:
new DisplayImageFromFTP_3.Async_GetImageFromFTP(this).execute();
and getting this error:
Error: DisplayImageFromFTP_3 is not an enclosing class
I would like to avaoid using static as suggested by Android Studio because it causes problems for a lot of objects in DisplayImageFromFTP_3, so perhaps I need the correct context?