小编Nag*_*kr.的帖子

如何使用RecyclerView完成Adapter类的活动

我正在尝试Recyclerview使用代码单击项目时完成适配器类的活动

public void onBindViewHolder(@NonNull CountryCodeAdapter.CountryViewHolder holder, int position{
    CountryModel countryMode = countryModels.get(position);
    final String cCode = countryModel.getName();
    holder.llcountryCode.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(v.getContext(),RegisterActivity.class);                        
            i.putExtra("countryCode", cCode);
            v.getContext().startActivity(i);
            ((AppCompatActivity)context).finish();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

也尝试过这个但是没用

((Activity)context).finish();
Run Code Online (Sandbox Code Playgroud)

我得到这个错误:

cannot be cast to android.support.v7.app.AppCompatActivity
Run Code Online (Sandbox Code Playgroud)

android adapter android-recyclerview

0
推荐指数
1
解决办法
1063
查看次数

标签 统计

adapter ×1

android ×1

android-recyclerview ×1