私はアンドロイドプロジェクトで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;
}
がFirebaseデータベースから取得したURLを正常にフェッチしています。
ここで何が問題になっているか教えてください。
申し訳ありませんが、質問のフォーマットが間違っています。私はまだ初心者です。
おかげで多く、先生(私もこのコードスニペットを追加しました)。問題は、 'bindView()'メソッドに画像読み込みロジックを置くときに 'itemView'というシンボルを解決できません。 –
コードを調整しました – mikepenz