[Solved] code go to other activity from main activty Adapter [closed]


Declare new variable in adapter

Context mContext;

replace your adapter constructor

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

    }

with below

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

intialize your adapter

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

now where you want to call new activity just put

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

if you want to call new activity on recycleview adapter replace below in your adapter

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

        }
    });

        }

10

solved code go to other activity from main activty Adapter [closed]