我使用此expandable recycler view库和Android注释。并尝试使用@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解决这个问题?
答案 0 :(得分:0)
您无法将ViewHolder
注释为@EBean
,因为@EBean
需要构造函数参数,而ViewHolder
需要View构造函数参数。
但是,在修改后的适配器的帮助下,您可以使用@EViewGroup
代替@EBean
。请参阅示例here。