Androidannotations EBean annotated class 应该有一个带有一个上下文类型参数的构造函数

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

我使用这个 expandable recycler view 库和 Android 注释。并尝试使用 @NonConfigurationInstance 注释。在 ItemViewHolder class 构造函数中,我需要 View 类型参数,但 @EBean 注释不允许在构造函数中使用除 Context 之外的任何参数。

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

这是我的 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;
    }
}

当我在构造函数中需要 View itemView 参数时,如何使用 androidannotations 解决这个问题?

不能将ViewHolders注解为@EBeans,因为@EBeans需要构造函数参数,而ViewHolder需要View构造函数参数。

但是,您可以使用 @EViewGroup 而不是 @EBean,借助修改后的适配器。请参阅示例 here