There is an adapter:

public class AdapterInfoContact extends RecyclerView.Adapter<RecyclerView.ViewHolder> { List<CountryCallingCode> valueContact = new ArrayList<>(); Context context; RecyclerItemClick itemClick; public AdapterInfoContact(Context context, List<CountryCallingCode> features) { this.valueContact = features; this.context = context; } @Override public int getItemViewType(int position) { return 0; } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { RecyclerView.ViewHolder viewHolder = null; LayoutInflater inflater = LayoutInflater.from(parent.getContext()); switch (viewType) { case 0: View item_Header = inflater.inflate(R.layout.item_filter, parent, false); viewHolder = new ValHolder(item_Header); break; } return viewHolder; } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { switch (holder.getItemViewType()) { case 0: ValHolder commentHolder = (ValHolder) holder; configureHeaderView(commentHolder, position); break; } } private void configureHeaderView(ValHolder valueHolder, int position) { if (valueContact.get(position).getInfo() != null) { if (position == 0) { valueHolder.mTvTitle.setText(valueContact.get(position).getInfo().getLogin()); } else if (position == valueContact.size() - 1) { try { if (valueContact.get(position).getInfo().getLocationCountry() != null && valueContact.get(position).getInfo().getLocationCountry().getValue() != null) valueHolder.mTvTitle.setText(valueContact.get(position).getInfo().getLocationCountry().getValue() + "," + valueContact.get(position).getInfo().getLocationRegion().getValue()); } catch (Exception e) { valueHolder.mTvTitle.setText(context.getString(R.string.country_tag)); } } } else { valueHolder.mTvTitle.setText("(" + valueContact.get(position).getCountryCode() + ") " + valueContact.get(position).getNationalNumber()); } } @Override public int getItemCount() { return valueContact.size(); } class ValHolder extends RecyclerView.ViewHolder implements View.OnClickListener { @BindView(R.id.title_filter) TextView mTvTitle; public ValHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); itemView.setOnClickListener(this); } @Override public void onClick(View v) { if (getAdapterPosition() == 0) { itemClick.itemLogin(valueContact.get(0).getInfo(), v); } else if (getAdapterPosition() == valueContact.size() - 1) { itemClick.itemMap(valueContact.get(getAdapterPosition()).getInfo(), v); } else { itemClick.itemContact(valueContact.get(getAdapterPosition()), v); } } } public interface RecyclerItemClick { void itemContact(CountryCallingCode code, View view); void itemLogin(Ad info, View view); void itemMap(Ad info, View view); } public void SetOnItemClickListener(final RecyclerItemClick mItemClickListener) { this.itemClick = mItemClickListener; } } 

I would like to place the pictures in such a way as to get a list, BUT already with pictures). Please tell me how it can be done more painlessly.

item_filter Code:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/title_filter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="@dimen/_10sdp" android:maxLines="1" /> <TextView android:id="@+id/value_filter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxLines="1" android:layout_alignParentRight="true" android:gravity="right" android:layout_marginRight="@dimen/_10sdp" android:layout_marginTop="@dimen/_10sdp" android:layout_marginBottom="@dimen/_10sdp" android:layout_toRightOf="@+id/title_filter" android:layout_toEndOf="@+id/title_filter" /> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="0.5dp" android:background="@color/new_divider" /> </LinearLayout> 
  • В котором как Вы уже наверное успели заметить есть два RecyclerView. - What is it like? - post_zeew
  • @post_zeew updated the question - Inkognito

1 answer 1

Add an ImageView to item_filter.xml (remembering to specify the attributes that will determine its location):

 <ImageView android:id="@+id/my_image_view" android:layout_width="100dp" android:layout_height="100dp"/> 

In ValHolder add:

 @BindView(R.id.my_image_view) ImageView mMyImageView; 

Add to the Drawable image my_image .

In the configureHeaderView(...) method, install this image:

 mMyImageView.setImageResource(R.drawable.my_image); 

UPD.

If for each item you need a separate icon, then it is better to add a field of type int in CountryCallingCode , in which the resource identifier (in this case, the image) will be stored and make the appropriate getter (for example, getImageId() ).

Then in configureHeaderView(...) do something like this:

 mMyImageView.setImageResource(valueContact.get(position).getImageId()); 
  • Super, only I have an icon for each item in the list. Do I need to additionally create an array or how best to assign the item corresponding to the icon? - Inkognito
  • @Inkognito, See UPD . - post_zeew
  • Sorry, but I hope the last clarification, you wrote in which the resource identifier will be stored - I wrote in CountryCallingCode just like this private int ImageId; Well, got a getter. This is not enough, because it is not used anywhere. - Inkognito
  • @Inkognito, Of course not enough. You transfer to the adapter a (already populated) collection of List<CountryCallingCode> features . Here, where you fill it (though not necessarily there), you must set the value of the mImageId field mImageId corresponding identifier. - post_zeew
  • it is not entirely clear how to set the field correctly , since it highlights the red ImageId in the adapter. And yet where is it to fill in? (Sorry, but it really doesn’t really work. - Inkognito