代码从主活动适配器转到其他 activity

code go to other activity from main activty Adapter

嗨,这是我的主要 Activity 请帮我 例如当我触摸 home show Activity home IDE(Android 工作室) http://flameit.ir/MainActivity.java

和我的适配器http://flameit.ir/MyAdapter.java

在适配器中声明新变量

Context mContext;

替换你的适配器构造函数

 MyAdapter(String Titles[], int Icons[], String Name, String Email, int Profile) {
        mNavTitles = Titles;
        mIcons = Icons;
        name = Name;
        email = Email;
        profile = Profile;

    }

以下

 MyAdapter(String Titles[], int Icons[], String Name, String Email, int Profile,Context cntx) {
        mNavTitles = Titles;
        mIcons = Icons;
        name = Name;
        email = Email;
        profile = Profile;
        mContext=cntx;
    }

初始化你的适配器

mAdapter = new MyAdapter(TITLES,ICONS,NAME,EMAIL,PROFILE,MainActivity.this);

现在你想在哪里调用新的activity就把

Intent itt=new Intent(mContext,YourNew.class);
mContext.startActivity(itt);

如果你想在 recycleview 适配器上调用新的 activity 替换下面的适配器

public ViewHolder(View itemView, int ViewType) {
            super(itemView);


            if (ViewType == TYPE_ITEM) {
                textView = (TextView) itemView.findViewById(R.id.rowText);
                imageView = (ImageView) itemView.findViewById(R.id.rowIcon);
                Holderid = 1;
            } else {


                Name = (TextView) itemView.findViewById(R.id.name);
                email = (TextView) itemView.findViewById(R.id.email);
                profile = (ImageView) itemView.findViewById(R.id.circleView);
                Holderid = 0;
            }
        itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        Intent itt=new Intent(mContext,YourNew.class);
        mContext.startActivity(itt);

        }
    });

        }