如何获取RecyclerView的项目视图

时间:2015-08-24 08:05:17

标签: android telerik adapter android-recyclerview radlistview

如何在Telerik的RadListViewRecyclerView中获取项目的观点; 例如:我希望TextViewImageView包含RadListView或{} RecyclerView

之前,我可以在getView() ListView之前获取,但现在我无法

我找了很多文件,但没有想法。

以下是我的adapter代码。

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 个答案:

答案 0 :(得分:0)

我有个主意:

创建一个界面:

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

在u活动或片段

中实现它
public class RemindActivity extends AppCompatActivity
    implements RadListViewClickListener{

     public void RadListViewClick(View v, int positon) {


     }
}
适配器中的

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());
        }
    }
}

这就是全部,任何人都有其他好的答案吗?我希望如此。 TY!