已创建Intent但startActivity方法无法识别

时间:2017-08-27 15:54:11

标签: android android-cardview

我尝试为我的cardView设置Onclick事件。如您所见,我在OnBindViewHolder中创建了该事件,但问题是startActivity方法无法识别。您认为我应该怎么做?提前谢谢你,对不起我的英语:)

public class AdapterVRList extends RecyclerView.Adapter<AdapterVRList.CourseViewHolder> {

private Context context;
private List<DObjectVrList> DObjectVrListList;

public AdapterVRList(Context context, List<DObjectVrList> DObjectVrListList){
    this.context = context;
    this.DObjectVrListList = DObjectVrListList;
}
public AdapterVRList(Context context){

}


@Override
public CourseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View view = LayoutInflater.from(context).inflate(R.layout.card_vr,parent,false);
    return new CourseViewHolder(view);
}

@Override
public void onBindViewHolder(CourseViewHolder holder, int position) {

    DObjectVrList DObjectVrList = DObjectVrListList.get(position);
    holder.CourseText.setText(DObjectVrList.getTitleCourse());

    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            CourseInnerPage course = new CourseInnerPage(getItemCount());
            Intent intent = new Intent(context,CourseInnerPage.class);
            startActivity(intent);
        }
    });
}

@Override
public int getItemCount() {
    return 8;
}

public class CourseViewHolder extends RecyclerView.ViewHolder{

    private TextView CourseText;

    public CourseViewHolder(View itemView) {
        super(itemView);
        CourseText = (TextView) itemView.findViewById(R.id.course_text);
    }
}
}

错误是:无法解析startActivity方法

2 个答案:

答案 0 :(得分:1)

因为您的适配器或其超类没有方法startActivity()

使用context.startActivity();

答案 1 :(得分:0)

使用context.startActivity(intent)