我在我的android项目中使用FastAdapter。ViewHolder不将该字符串设置为TextView的文本。请看详情
这是我如何使用它:
public class HRequest extends AbstractItem<HRequest, HRequest.ViewHolder> {
public String imageURL;
public HRequest() {
}
public HRequest(String imageURL) {
this.imageURL = imageURL;
}
// Fast Adapter methods
@Override
public int getType() {
return R.id.recycler_view;
}
@Override
public int getLayoutRes() {
return R.layout.h_request_list_row;
}
@Override
public void bindView(ViewHolder holder) {
super.bindView(holder);
holder.imageURL.setText(imageURL);
}
// Manually create the ViewHolder class
protected static class ViewHolder extends RecyclerView.ViewHolder {
TextView imageURL;
public ViewHolder(View itemView) {
super(itemView);
imageURL = (TextView)itemView.findViewById(R.id.imageURL);
if (!imageURL.getText().toString().isEmpty()) {
Toast.makeText(itemView.getContext(), imageUID.getText().toString(), Toast.LENGTH_SHORT).show();
if (imageURL.getText().toString().startsWith("https://firebasestorage.googleapis.com/") || imageURL.getText().toString().startsWith("content://")) {
Picasso.with(itemView.getContext())
.load(imageURL.getText().toString())
.into(homelessImage);
} else {
Toast.makeText(itemView.getContext(), "some problem", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(itemView.getContext(), "no imageUID found", Toast.LENGTH_SHORT).show();
}
}
}
}
这里是R.layout.h_request_list_row
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools">
<TextView
android:id="@+id/imageURL"
android:text="imageURL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
这里的问题是,imageURL
不获取设置为从数据库中,但作为imageURL
检索到的imageURL
在布局文件中定义,因此不会下载图像。我遵循了这一要点:https://gist.github.com/puf/f49a1b07e92952b44f2dc36d9af04e3c
我相信String imageURL
这里:
public HRequest(String imageURL) {
this.imageURL = imageURL;
}
已经成功地提取从火力地堡数据库中检索到的URL。
请让我知道这里发生了什么问题。
对不起,格式不正确的问题。我仍然是这里的初学者。
非常感谢,主席先生。现在,问题在于它显示了这种情况:'在将图像加载逻辑放入'bindView()'方法时,无法解析符号'itemView'。 –
调整了代码 – mikepenz