实现思路:
1.需要给工具类里传入context;
2.使用上下文mContext.startActivity启动activity
例子1:
public class SafePlaceRecyclerViewAdapter {
private Context mContext;
public SafePlaceRecyclerViewAdapter(Context context){
mContext = context;
}
public void start(){
Intent intent = new Intent(mContext,SafeAreaInformation.class);
mContext.startActivity(intent);
}
}
例子2:
public class SafePlaceRecyclerViewAdapter extends RecyclerView.Adapter<SafePlaceRecyclerViewAdapter.ViewHolder> {
private List <SafePlaceData> mList;
private Context mContext;
public SafePlaceRecyclerViewAdapter(Context context, List<SafePlaceData> list){
this.mList = list;
mContext = context;
}
@Override
public ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.safe_place_row_layout,parent,false);
ViewHolder viewHolder = new ViewHolder(view);
viewHolder.safePlaceRowLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(),SafeAreaInformation.class);
mContext.startActivity(intent);
}
});
return viewHolder;
}