android中gridView中点击 item为选中状态

时间:2021-02-24 15:33:32
 

gridView.setOnItemClickListener(new Gallery.OnItemClickListener(){
   @Override
   public void onItemClick(AdapterView<?> parent, View arg1, int position,long arg3) {
   portal_menu_gridView2.getAnimation();
   for(int i=0;i<parent.getCount();i++){
               View v=parent.getChildAt(i);
               if (position == i) {//当前选中的Item改变背景颜色
                arg1.setBackgroundResource(R.drawable.bottombg_h);
               } else {
                  v.setBackgroundResource(R.drawable.portal_navigation_1bottom);
               }
           }
   }});