Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8352595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:00:27+00:00 2026-06-09T09:00:27+00:00

I stuck with the project trying to make Page Slider between two activities. All

  • 0

I stuck with the project trying to make Page Slider between two activities.

  • All I know that each activity independently works, but when I try to set up PageAdapter for sliding putting:
  • Also, I write activity in Manifest, initialize all variables from XML in Java, but the problem starts exactly at the moment when I set up onClickListener for my buttons.

    LayoutInflater inflater = LayoutInflater.from(this);
    List pages = new ArrayList();

    View page = inflater.inflate(R.layout.photo, null);
    pages.add(page);
    page = inflater.inflate(R.layout.cameragrid, null);
    pages.add(page);
    
    CameraPagerAdapter pagerAdapter = new CameraPagerAdapter(pages);
    ViewPager viewPager = new ViewPager(this);
    viewPager.setAdapter(pagerAdapter);
    viewPager.setCurrentItem(0);    //view being shown firstly
    
    setContentView(viewPager); 
    

    instead of *setContentView(R.layout.photo);* it’s doesn’t launch.
    What did I missed? Thanks for advance.

First Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    makeAdditionalPageSlide(); //>>> problems started here

    initialize();

    InputStream is = getResources().openRawResource(R.drawable.dinam);
    bmp = BitmapFactory.decodeStream(is);
}
public void makeAdditionalPageSlide(){
    LayoutInflater inflater = LayoutInflater.from(this);
    List<View> pages = new ArrayList<View>();

    View page = inflater.inflate(R.layout.photo, null);
    pages.add(page);
    page = inflater.inflate(R.layout.cameragrid, null);
    pages.add(page);

    CameraPagerAdapter pagerAdapter = new CameraPagerAdapter(pages);
    ViewPager viewPager = new ViewPager(this);
    viewPager.setAdapter(pagerAdapter);
    viewPager.setCurrentItem(0);    //view being shown firstly

    setContentView(viewPager); 


}

private void initialize() {
    // TODO Auto-generated method stub
    iv = (ImageView) findViewById (R.id.ivReturnedPic);
    ib = (ImageButton) findViewById (R.id.ibTakePic);
    b = (Button) findViewById(R.id.bSetWall);
    b.setOnClickListener(this);
    ib.setOnClickListener(this);
}
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()){
    case R.id.bSetWall:
        try {
            getApplicationContext().setWallpaper(bmp);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        break;
    case R.id.ibTakePic:
        i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, cameraData);
    break;
    }
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK){
        Bundle extras = data.getExtras();
        bmp = (Bitmap) extras.get("data");
        iv.setImageBitmap(bmp);
    }
}

PageAdapter:

public class CameraPagerAdapter extends PagerAdapter  {
 List<View> pages = null;

    public CameraPagerAdapter(List<View> pages){
        this.pages = pages;
    }

    @Override
    public Object instantiateItem(View collection, int position){
        View v = pages.get(position);
        ((ViewPager) collection).addView(v, 0);
        return v;
    }

    @Override
    public void destroyItem(View collection, int position, Object view){
        ((ViewPager) collection).removeView((View) view);
    }

    @Override
    public int getCount(){
        return pages.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object){
        return view.equals(object);
    }

    @Override
    public void finishUpdate(View arg0){
    }

    @Override
    public void restoreState(Parcelable arg0, ClassLoader arg1){
    }

    @Override
    public Parcelable saveState(){
        return null;
    }

    @Override
    public void startUpdate(View arg0){
    }

}
the second Activity:

public class CameraGrid extends Activity implements OnItemClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cameragrid);
    GridView gv = (GridView) findViewById(R.id.cameragrid);
    CameraImageAdapter ia = new CameraImageAdapter(getApplicationContext());
    gv.setAdapter(ia);
    //gridview.setOnItemClickListener(this); 
    gv.setOnItemClickListener(this);
}

public void onItemClick(AdapterView<?> arg0, View iv, int position, long id) {
    // TODO Auto-generated method stub
    Toast.makeText(getApplicationContext(), ""+position, Toast.LENGTH_LONG).show();

    Intent i = new Intent(getApplicationContext(),CameraImageDetails.class);
    i.putExtra("id", position);
    startActivity(i);

}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:00:28+00:00Added an answer on June 9, 2026 at 9:00 am

    My recommendation is to make mainActivity.xml layout with placeholder for ViewPager and setContentView(R.layout.mainActivity)

    Things related to content of page view u setup in PageViewAdapter.

    Maybe I didn’t quite understand logic u tried to do it, but it seems a bit confusing.. :S

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to achieve two-way binding between a DataGridView and a BindingList that provides
Hey, I'm really stuck with my project here... I need to know when any
I am using CoreData for an iPhone project and I am stuck trying to
I'm trying to make a transition from vb.net to C++ and I'm stuck on
I am currently trying to make an existing VB.NET Project run. A null pointer
I'm trying to build a project in JavaScript that utilizes HTML5's canvas tag. However,
I got stuck trying to make a ManyToMany cascading event to work. I've bean
I'm trying to build some functionality for a project, but I'm stuck with this:
I'm trying to add a Chinese version of my Strings.xml (into a project that
I'm trying to make a deliberate effort to write code that follows proper convention,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.