gpt4 book ai didi

java - Androidannotations EBean注释类应该有一个带有一个Context类型参数的构造函数

转载 作者:太空宇宙 更新时间:2023-11-04 12:03:36 25 4
gpt4 key购买 nike

我用这个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 修复此问题?

最佳答案

您不能将 ViewHolder 注释为 @EBean,因为 @EBean 需要构造函数参数,而 ViewHolder 需要 View 构造函数参数。

但是,您可以在修改后的适配器的帮助下使用@EViewGroup 代替@EBean。请参阅示例 here .

关于java - Androidannotations EBean注释类应该有一个带有一个Context类型参数的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40651868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com