2013-12-17 2 views
0

나는 안드로이드를 처음 사용하며 그리드 뷰를 사용하는 방법을 모릅니다. 항목의 끝에있는 이미지 형식의 격자보기가 필요합니다. 그리드보기에서 마지막 이미지 뷰 앞에 imageview를 추가해야합니다.이 그리드 뷰에는 imageview가 있으며, s.It shuld는 동적으로 imageview를 추가합니다. 제발 도와주세요동적 이미지를 마지막 이미지 뷰에 추가하십시오. 그리드보기

Grid view

+0

RU가 설정하는 사용자 정의 어댑터를 사용하여 그리드보기 데이터 ?? –

답변

0
  • GridView는 어댑터에 의해 백업됩니다. 그런 당신은 데이터 세트에서 주어진 위치에 대한 뷰를 생성하는 어댑터의 getView() 기능을 사용

당신이 할 필요가 목록으로 BaseAdapter 또는 ListAdapter

  • 어댑터가 데이터 집합에 의해 백업됩니다 봐 N + 1 개의 요소가있는 목록을 만드십시오. 여기서 N은 표시 할 이미지의 수이고 +1은 추가 버튼입니다.

    이미지가 추가되면 목록의 두 번째 마지막 위치에 추가합니다. 그런 다음 어댑터 notifyDataSetChanged()을 호출합니다. 이렇게하면 GridView를 새 백업 데이터로 새로 고칩니다.

  • 0

    시도 다음 adaper : 활동

    :

    private List<Bitmap> images=new List<Bitmap>(); 
    images.add(<LastImage>); 
    MyAdapter adapter=new MyAdapter(this,images); 
    gridView.setAdapter(adapter); 
    

    새 항목을 추가하는 동안 :

    adapter.addImage(<NewBitmap>); 
    

    어댑터 :

    public class MyAdapter extends ArrayAdapter<Bitmap> { 
    
        private List<Bitmap> images; 
        private Context context; 
    
        public MyAdapter(Context context, 
          List<Bitmap> images) { 
         super(context,0, images); 
         this.images = images; 
         this.context = context; 
        } 
    
        @Override 
        public View getView(int position, View convertView, ViewGroup parent) { 
         ImageView image=(ImageView)convertView; 
         if (image == null) { 
          image = new ImageView(context); 
         } 
         imageView.setImageBitmap(images.get(position)); 
         return imageView; 
        } 
    
        public void addImage(Bitmap image) { 
         images.add(images.size()-1,image); 
         this.notifyDataSetChanged(); 
        } 
    } 
    
    관련 문제