2013-10-29 2 views
0

확인란을 선택하면 아이콘이 bitmapdrawable로 바뀝니다. 그런 다음 비트 맵 드로어 블을 gridView에 표시 할 수있게하려고합니다. 나는이 일을 할 수없는 것 같습니다. 여기 내 체크 박스입니다 : 내가 일을 대신 정수의 ArrayList를 그리기를 시도 들었다하나의 클래스에서 drawable을 gridView로 가져 오는 데 도움이 필요합니다.

package com.example.awesomefilebuilderwidget; 

IMPORTS 

public class GridView extends Activity implements OnItemLongClickListener, OnDragListener{ 

ArrayList<Integer> drawables = new ArrayList<Integer>(); 

private BaseAdapter adapter; 
private int draggedIndex = -1; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.drag_and_drop_app); 
    drawables = new ArrayList<Integer>(); 
    drawables.add(R.drawable.pattern1); 
    drawables.add(R.drawable.pattern2); 
    android.widget.GridView gridView = (android.widget.GridView) findViewById(R.id.grid_view); 
    gridView.setOnItemLongClickListener(this); 
    gridView.setAdapter(adapter = new BaseAdapter() { 

     @Override 
     // Get a View that displays the data at the specified position in 
     // the data set. 
     public View getView(int position, View convertView, 
       ViewGroup gridView) { 
      // try to reuse the views. 
      ImageView view = (ImageView) convertView; 
      // if convert view is null then create a new instance else reuse 
      // it 
      if (view == null) { 
       view = new ImageView(GridView.this); 
      } 
      view.setImageResource(drawables.get(position)); 
      view.setScaleType(ImageView.ScaleType.CENTER_CROP); 
      view.setLayoutParams(new android.widget.GridView.LayoutParams(70, 70)); 
      view.setTag(String.valueOf(position)); 
      return view; 
     } 

     @Override 
     // Get the row id associated with the specified position in the 
     // list. 
     public long getItemId(int position) { 
      return position; 
     } 

     @Override 
     // Get the data item associated with the specified position in the 
     // data set. 
     public Object getItem(int position) { 
      return drawables.get(position); 
     } 

     @Override 
     // How many items are in the data set represented by this Adapter. 
     public int getCount() { 
      return drawables.size(); 
     } 
    }); 
} 

: 여기 내 GRIDVIEW에 표시하는 drawablebitmap를 얻기 위해 노력하고 있어요 그런

addCheckbox 
      .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 

       @Override 
       public void onCheckedChanged(CompoundButton buttonView, 
         boolean isChecked) { 
        if (addCheckbox.isChecked()) { 
         System.out.println("Checked"); 
         PackageManager pm = mContext.getPackageManager(); 
         Drawable icon = null; 
         try { 
          icon = pm 
            .getApplicationIcon(entry.packageName); 
         } catch (NameNotFoundException e) { 
          // TODO Auto-generated catch block 
          e.printStackTrace(); 
         } 
         Drawable default_icon = pm.getDefaultActivityIcon(); 
         if (icon instanceof BitmapDrawable 
           && default_icon instanceof BitmapDrawable) { 
          BitmapDrawable icon_bd = (BitmapDrawable) icon; 
          Bitmap icon_b = icon_bd.getBitmap(); 
          BitmapDrawable default_bd = (BitmapDrawable) pm 
            .getDefaultActivityIcon(); 
          Bitmap default_b = default_bd.getBitmap(); 
          if (icon_b == default_b) { 
           // It's the default icon 
          } 
         } 
        } else { 
         System.out.println("Un-Checked"); 
        } 

       } 

그래도 괜찮지 만 비트 맵을 추가하는 방법은 잘 모르겠습니다.

내 체크 박스 onCheckedChange 메서드에서 만든 비트 맵을 내 gridView에 추가하려면 어떻게해야합니까?

답변

0

Integer 대신 ArrayList Drawable을 사용하는 경우 비트 맵을 해당 드로어 블 배열에 추가 한 다음 어댑터의 notifyDataSetChanged() 함수를 호출해야합니다. 그것은 같은 것입니다

drawables.add(default_bd); 
adapter.notifyDataSetChanged() 
관련 문제