简体   繁体   中英

Why I cant make an intent in my “public class adapter extends PagerAdapter” to MainActivity2s

this is a click listener for pages of view pager

view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (position){
                    case 0:
                        Intent intent = new Intent(MainActivity.this,MainActivity2s.class);**
                        context.startActivity(intent);
                    break;
                    case 1:
                        Toast.makeText(context,"intent Tow ",Toast.LENGTH_SHORT).show();
                    break;
                    case 2:
                        Toast.makeText(context,"intent Three ",Toast.LENGTH_SHORT).show();
                    break;

                }
            }
        });

**=> there i get this error ('com.example.app.MainActivity' is not an enclosing class)

I think your adapter is not an inner class of MainActivity , thus you cannot call MainActivity.this . I'm guessing what you are trying to do and what you should do rather is to populate fragments not activities when ViewPager is scrolled.

You may take a look here if that is the case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM