在android gridview中的图标集之间切换

时间:2014-03-08 08:57:26

标签: android gridview notifydatasetchanged

我是Android开发的新手。在我的机器activity中,我有一个GridView和一个ButtonGridView adapter班级在GridView中显示一组图标。我想要的是,如果点击活动中的ButtonGridView中的图标集应该被另一组图标替换。并且活动中的每次Button点击都会切换GridView中的两组图标。 那么,如何使用notifyDatasetChanged()执行此操作?请帮助。

GridView Adapter上课:

public class CustomAdapter extends BaseAdapter{

        boolean imageSetChange = false;

        // set 1
        public Integer[] mThumbPics = {
                  R.drawable.pic1, R.drawable.pic2,
                    R.drawable.pic3, R.drawable.pic4,
                    R.drawable.pic5, R.drawable.pic6,
                    R.drawable.pic7, R.drawable.pic8,
                    R.drawable.pic9, R.drawable.pic10,
                    R.drawable.pic11, R.drawable.pic12,
                    R.drawable.pic13, R.drawable.pic14,
                    R.drawable.pic15, R.drawable.pic16,
                    R.drawable.pic17, R.drawable.pic18,
                    R.drawable.pic19, R.drawable.pic20,
                    R.drawable.pic21

        };
        //set 2
        public Integer[] mThumbEng = {
                R.drawable.eng_pic1, R.drawable.eng_pic2,
                R.drawable.eng_pic3, R.drawable.eng_pic4,
                R.drawable.eng_pic5, R.drawable.eng_pic6,
                R.drawable.eng_pic7, R.drawable.eng_pic8,
                R.drawable.eng_pic9, R.drawable.eng_pic10,
                R.drawable.eng_pic11, R.drawable.eng_pic12,
                R.drawable.eng_pic13, R.drawable.eng_pic14,
                R.drawable.eng_pic15, R.drawable.eng_pic16,
                R.drawable.eng_pic17, R.drawable.eng_pic18,
                R.drawable.eng_pic19, R.drawable.eng_pic20,
                R.drawable.eng_pic21
               };

        private Context mContext;
        View MyView;
        ImageView imageView;

        public CustomAdapter(Context c){
            mContext = c;
        }

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

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return mThumbEng[position];
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            if(imageSetChange==false)
            {if(convertView == null){

                    LayoutInflater li=((Activity) mContext).getLayoutInflater();
                    MyView=li.inflate(R.layout.menuitem, null);

                    }
                    else{
                        MyView=(View)convertView;
                    }
                imageView =(ImageView)MyView.findViewById(R.id.image);

                imageView.setImageResource(mThumbEng[position]);

                       return MyView;
                       }
            else{

                if(convertView == null){

                    LayoutInflater li=((Activity) mContext).getLayoutInflater();
                    MyView=li.inflate(R.layout.menuitem, null);

                    }
                    else{
                        MyView=(View)convertView;
                    }
                imageView =(ImageView)MyView.findViewById(R.id.image);

                imageView.setImageResource(mThumbUrdu[position]);

                       return MyView;


            }


        }   

        /** public void changeImages(boolean change){
            this.imageSetChange  = change;

            cda.notifyDataSetChanged();

        }
    **/

}

按钮onclick听众:

Button lang_change_btn = (Button) findViewById(R.id.button1);
        lang_change_btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                // TODO Auto-generated method stub

                //cda.changeImages(true);


            }
        });

0 个答案:

没有答案