Advertisement
Guest User

Untitled

a guest
May 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.10 KB | None | 0 0
  1.     private class ImageAdapter extends BaseAdapter {
  2.         private static final String IMAGES_PATH = "images";
  3.  
  4.         private Context  context;
  5.  
  6.         private String[] display_names;
  7.         private String[] basenames;
  8.        
  9.         public ImageAdapter(Context context) {
  10.             this.context  = context;
  11.             display_names = getResources().getStringArray(R.array.sound_display_names);
  12.             basenames     = getResources().getStringArray(R.array.sound_basenames);
  13.         }
  14.        
  15.         public int getCount() {
  16.             return basenames.length;
  17.         }
  18.        
  19.         public Object getItem(int position) {
  20.             return basenames[position];
  21.         }
  22.  
  23.         public long getItemId(int position) {
  24.             return position;
  25.         }
  26.  
  27.         public View getView(int position, View convertView, ViewGroup parent) {
  28.             LinearLayout view;
  29.            
  30.             if (convertView == null) {
  31.                 view = (LinearLayout)MainActivity.this.getLayoutInflater().inflate(R.layout.list_item, null);
  32.             } else {
  33.                 view = (LinearLayout)convertView;
  34.             }
  35.  
  36.             ImageView image = (ImageView)view.findViewById(R.id.item_image);
  37.             String filename = basenames[position] + ".jpg";
  38.  
  39.             Log.d(TAG, "!!! " + filename);
  40.            
  41.             image.setLayoutParams(new GridView.LayoutParams(85, 85));
  42.             image.setScaleType(ImageView.ScaleType.CENTER_CROP);
  43.             image.setPadding(8, 8, 8, 8);
  44.  
  45.             // try {
  46.                 // Drawable data = Drawable.createFromStream(MainActivity.this.getAssets().open(IMAGES_PATH + "/" + filename),
  47.                 //                                           filename);
  48.                 // image.setImageDrawable(data);
  49.             // } catch(java.io.IOException e) {
  50.             //     Log.d(TAG, "Could not load image " + filename + ": " + e);
  51.             // }
  52.  
  53.             TextView text = (TextView)view.findViewById(R.id.item_text);
  54.             text.setText(display_names[position]);
  55.  
  56.             return view;
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement