Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having problem in making the view visible and invisible in viewpager.My requirement is i want to make the view invisible on click of a button or a image,but this action is happening on the next consecutive page. Here is the adapter class which i have tried.

C#
public ViewPagerAdapter(MainActivity mainActivity, int noofsize) {
    // TODO Auto-generated constructor stub
    size = noofsize;
    act = mainActivity;
}


C#
//Override
public int getCount() {
    // TODO Auto-generated method stub
    return size;
}


C#
//Override
public Object instantiateItem(View container, int position) {
    // TODO Auto-generated method stub
    LayoutInflater inflater = (LayoutInflater) act
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layout = inflater.inflate(R.layout.viewpages, null);
    click = (Button) layout.findViewById(R.id.click);
    text = (TextView) layout.findViewById(R.id.text);
    click.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            text.setVisibility(View.INVISIBLE);
        }
    });
    ((ViewPager) container).addView(layout, 0);
    return layout;
}


C#
//Override
public void destroyItem(View arg0, int arg1, Object arg2) {
    ((ViewPager) arg0).removeView((View) arg2);
}


C#
//Override
public boolean isViewFromObject(View arg0, Object arg1) {
    return arg0 == ((View) arg1);
}


C#
//Override
public Parcelable saveState() {
    return null;
}


And Activity class is as follows

C#
public class MainActivity extends Activity {

int noofsize = 4;

//Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ViewPagerAdapter adapter = new ViewPagerAdapter(MainActivity.this,
            noofsize);
    ViewPager myPager = (ViewPager) findViewById(R.id.reviewpager);
    myPager.setAdapter(adapter);
    myPager.setCurrentItem(0);
}
Posted
Updated 28-Jul-13 23:22pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900