我使用这个可扩展的回收器视图库和 Androidannotations。并尝试使用 @NonConfigurationInstance 注释。在 ItemViewHolder 类构造函数中,我需要 View 类型参数,但 @EBean 注释不允许在构造函数中使用除 Context 之外的任何参数。
Error: org.androidannotations.annotations.EBean annotated element should have a constructor with one parameter max, of type android.content.Context
这是我的 ItemViewHolder 类:
@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 解决此问题?