javaandroidebeanandroid-annotationsexpandablerecyclerview

Androidannotations EBean annotated class should have a constructor with one parameter of Context type


I use this expandable recycler view library and Androidannotations. And try to use @NonConfigurationInstance annotation. In ItemViewHolder class constructor I need View type argument, but @EBean annotation does not allow to use any parametr in constructor except Context.

Error: org.androidannotations.annotations.EBean annotated element should have a constructor with one parameter max, of type android.content.Context

This is my ItemViewHolder class:

@EBean
public class TextsItemViewHolder extends ChildViewHolder {
    public static final String LOG_TAG = "TextsFrLog";
    private TextView title;
    public TextView progrInfo;
    public TextView fileSize;
    public static ProgressBar bar;
    public Button downlbtn;
    public Button openbtn;
    public Button delbtn;
    public Button cancelbtn;
    Toast toast;

    @NonConfigurationInstance
    @Bean
    DownloadFileAsync downloadTask;
   @RootContext
   MainActivity context;


    public TextsItemViewHolder(@NonNull View itemView) {
        super(itemView);
        title = (TextView) itemView.findViewById(R.id.textTitleChild);
        bar = (ProgressBar) itemView.findViewById(R.id.downloadProgressBar);
        downlbtn = (Button)itemView.findViewById(R.id.downloadButton);
        openbtn = (Button) itemView.findViewById(R.id.opendButton);
        delbtn = (Button) itemView.findViewById(R.id.deleteButton);
        cancelbtn = (Button) itemView.findViewById(R.id.cancelButton);
        progrInfo = (TextView) itemView.findViewById(R.id.procentage);
    }

    public void bind(@NonNull TextItem textItem) {
        title.setText(textItem.getTextTitle());
        String servername = textItem.getServername();
        final String linktitle = textItem.getLink();
        final String ziptitle = textItem.getZipTitle();
        final String linkforDownload = servername + linktitle + ziptitle + ".zip";


        downlbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(LOG_TAG, "Click downlbt" + linktitle + ziptitle);
                if(isOnline()){
                    downloadTask.loadInBackground(linkforDownload, linktitle, ziptitle);
                }
                else {
                    toast = Toast.makeText(context, context.getResources().getString(R.string.notification_no_internet), Toast.LENGTH_SHORT);
                    toast.show();
                }
            }
        });
    }


    public static void updateChildRow(int progress) {
        bar.setProgress(progress);
    }
    boolean isOnline() {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        return cm.getActiveNetworkInfo() != null;
    }
}

How can I fix this with androidannotations, when I need in constructor the View itemView parameter?


Solution

  • You cannot annotate ViewHolders as @EBeans, because @EBeans need a constructor parameter, while ViewHolder needs a View constructor parameter.

    However, you can use @EViewGroup instead of @EBean, with the help of a modified adapter. See the example here.