0

请帮我解决这些问题,我被困住了

我正在使用 viewpager,我需要我的线性布局更改它在单击按钮时的可见性,但可见性属性似乎但不起作用。

这是我的代码

public class MyPagerAdapter extends PagerAdapter {

        @Override
        public Object instantiateItem(final View collection, final int position) {
            Log.d("Inside", "Pager");
            PagerView = new View(collection.getContext());
            LayoutInflater inflater = (LayoutInflater) collection.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            PagerView = inflater.inflate(R.layout.bigimage, null);
            imgSubmenu = (ScalableImageView)PagerView.findViewById(R.id.imgSubMenu);
            btnBack = (Button)PagerView.findViewById(R.id.btnBack);
            btnCart = (Button) PagerView.findViewById(R.id.btnCart);
            btnCallWaiter = (Button) PagerView.findViewById(R.id.btnCallWaiter);
            btnPayBill = (Button) PagerView.findViewById(R.id.btnPayBill);
            btnReadMore = (Button) PagerView.findViewById(R.id.btnReadMore);
            btnAddtoOrder = (Button) PagerView.findViewById(R.id.btnAddtoOrder);
            tvSubMenuName = (TextView) PagerView.findViewById(R.id.tvSubMenuName);
            tvDescption = (TextView) PagerView.findViewById(R.id.tvDescrption);
            readLayout=(LinearLayout)PagerView.findViewById(R.id.readLayout);
            font = Typeface.createFromAsset(MenuSelectionActivity.this.getAssets(),
                    "fonts/BEBAS___.ttf");
            btnBack.setTypeface(font, Typeface.BOLD);
            btnCallWaiter.setTypeface(font, Typeface.BOLD);
            btnPayBill.setTypeface(font, Typeface.BOLD);
            btnReadMore.setTypeface(font, Typeface.BOLD);
            tvSubMenuName.setTypeface(font, Typeface.BOLD);
            btnReadMore.setTypeface(font, Typeface.BOLD);
            tvDescption.setTypeface(font, Typeface.BOLD);
            btnAddtoOrder.setTypeface(font, Typeface.BOLD);
            ((ViewPager) collection).addView(PagerView, 0);
            DisplayItem(position);
            btnReadMore.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Log.d("readtype",""+readtype);
                    if(readtype==0)
                    {
                        readLayout.setVisibility(View.GONE);
                        btnReadMore.setText("READ MORE");
                        btnReadMore.setBackgroundResource(drawable.readmore);
                        readtype=1;

                    }
                    else
                    {
                        readLayout.setVisibility(View.VISIBLE);
                        btnReadMore.setText("READ LESS");
                        btnReadMore.setBackgroundResource(drawable.readless);                   
                        readtype=0;
                    }
                }
            });
            btnBack.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    finish();
                }
            });
            return PagerView;
        }

        @Override
        public void destroyItem(final View arg0, final int arg1,
                final Object arg2) {
            ((ViewPager) arg0).removeView((View) arg2);

        }

        @Override
        public boolean isViewFromObject(final View arg0, final Object arg1) {
            return arg0 == ((View) arg1);

        }

        @Override
        public void finishUpdate(View arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void restoreState(Parcelable arg0, ClassLoader arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public Parcelable saveState() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public void startUpdate(View arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return SubMenuIdList.size();
        }

    } 

谁能帮帮我。

4

1 回答 1

0

我认为您的代码是正确的。你试过用int设置可见性吗?

setVisibility(0) -> visible  or setVisibility(View.VISIBLE)
setVisibility(4) -> invisible or setVisibility(View.INVISIBLE)
setVisibility(8) -> gone or setVisibility(View.GONE)
于 2013-10-25T12:58:40.343 回答