How to get item 's view of RecyclerView

207 Views Asked by At

How to get item 's view in RadListView of Telerik or RecyclerView; For Example :I want to get TextView or ImageView included item of RadListView or RecyclerView.

Before,I can get it by getView() in ListView,but now I can't;

I have looked for many document,but no ideas .

The following is my adapter code.

public class ReminderAdapter extends ListViewAdapter {

private List<Map<String, Object>> dataList;
private Context mContext;

public ReminderAdapter(List items, Context context) {
    super(items);
    this.dataList = items;
    mContext = context;
}

@Override
public ListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(mContext).
            inflate(R.layout.remind_custom_radlistview_item, parent, false);
    return new ReminderViewHolder(view);

}

@Override
public void onBindViewHolder(ListViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);
    ReminderViewHolder reminderViewHolder = (ReminderViewHolder) holder;
    reminderViewHolder.timeTextView.setText((String) dataList.get(position).get("time"));
    reminderViewHolder.remainTextView.setText((String) dataList.get(position).get("remain"));
    reminderViewHolder.selectImageView.setImageResource((Integer) dataList.get(position).get("pic"));
    if (position == dataList.size() - 1) {
        reminderViewHolder.mView.setVisibility(View.GONE);
    }

}


class ReminderViewHolder extends ListViewHolder {

    TextView timeTextView;

    TextView remainTextView;

    ImageView selectImageView;

    View mView;
    MaterialRippleLayout materialRippleLayout;

    public ReminderViewHolder(View itemView) {
        super(itemView);
        timeTextView = (TextView) itemView.findViewById(R.id.custom_remind_list_timeTextView);
        remainTextView = (TextView) itemView.findViewById(R.id.custom_remind_list_remainTextView);
        selectImageView = (ImageView) itemView.findViewById(R.id.custom_remind_list_selectImage);
        mView = (View) itemView.findViewById(R.id.custom_remind_list_horizontal_line);
        materialRippleLayout = (MaterialRippleLayout) itemView.findViewById(R.id.acustom_remind_list_ripple_layout);
    }
}
}
1

There are 1 best solutions below

0
On BEST ANSWER

I have an idea:

creat a interface:

public interface RadListViewClickListener {
   public void RadListViewClick(View v,int positon);
}

implements it in u activity or fragment

public class RemindActivity extends AppCompatActivity
    implements RadListViewClickListener{

     public void RadListViewClick(View v, int positon) {


     }
}

in u adapter

public class ReminderAdapter extends ListViewAdapter {

private List<Map<String, Object>> dataList;
private Context mContext;
private  RadListViewClickListener mListener;
public ReminderAdapter(List items, Context context,RadListViewClickListener listener) {
    super(items);
    this.dataList = items;
    this.mContext = context;
    this.mListener=listener;
}
    class ReminderViewHolder extends ListViewHolder implements View.OnClickListener {

    TextView timeTextView;

    TextView remainTextView;

    ImageView selectImageView;

    View mView;

    public ReminderViewHolder(View itemView) {
        super(itemView);

        timeTextView = (TextView) itemView.findViewById(R.id.custom_remind_list_timeTextView);
        remainTextView = (TextView) itemView.findViewById(R.id.custom_remind_list_remainTextView);
        selectImageView = (ImageView) itemView.findViewById(R.id.custom_remind_list_selectImage);
        mView = (View) itemView.findViewById(R.id.custom_remind_list_horizontal_line);
        itemView.setOnclickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mListener.RadListViewClick(itemView,getAdapterPosition());
            }
        });
    }

    @Override
    public void onClick(View v) {
        if(v instanceof  MaterialRippleLayout){
            mListener.RadListViewClick(selectImageView,this.getPosition());
        }
    }
}

this is all, anyone have other good answer? i hope it. ty!