Android Open Source - CakeUI Cake Grid View Adapter






From Project

Back to project page CakeUI.

License

The source code is released under:

GNU General Public License

If you think the Android project CakeUI listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cakeui.generic.adapter;
//  ww  w  .ja  v a 2 s .c  o  m
import java.util.List;

import com.cakeui.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 
 * @author Mariana Azevedo
 * @email mariana@bsi.ufla.br
 * 
 * 
 * Class that implements a generic GridView Adapter.
 *
 */

public class CakeGridViewAdapter extends BaseAdapter{

  private Context context;
  private List<Integer> itemsIconsArray;
  private List<String>  itemsNamesArray;
  
  public CakeGridViewAdapter(Context context, List<Integer> itemsIconsArray, List<String> itemsNamesArray) {
    this.context = context;
    this.itemsIconsArray = itemsIconsArray;
    this.itemsNamesArray = itemsNamesArray;
  }
  
  @Override
  public int getCount() {
    return itemsIconsArray.size();
  }

  @Override
  public Object getItem(int position) {
    return itemsIconsArray.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    
    ViewHolder viewHolder;
    
    if (convertView == null){
      
      LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = inflater.inflate(R.layout.activity_gridview_items, parent, false);
      
      viewHolder = new ViewHolder();
      
      viewHolder.itemsNamesTextView = (TextView) convertView.findViewById(R.id.gridViewItem);
      convertView.setTag(viewHolder);
      
    }else{
      viewHolder = (ViewHolder) convertView.getTag();
    }
    viewHolder.itemsNamesTextView.setText(itemsNamesArray.get(position));
    viewHolder.itemsNamesTextView.setCompoundDrawablesWithIntrinsicBounds(null, context.getResources().getDrawable(itemsIconsArray.get(position)), 
        null, null);
    
    return convertView;
  }
  
  static class ViewHolder{
    TextView itemsNamesTextView;
  }
}




Java Source Code List

com.cakeui.application.CakeApplication.java
com.cakeui.generic.activity.CakeActivity.java
com.cakeui.generic.adapter.CakeExpandableListViewAdapter.java
com.cakeui.generic.adapter.CakeGridViewAdapter.java
com.cakeui.generic.adapter.CakeListViewAdapter.java
com.cakeui.generic.dialog.CakeDialog.java
com.cakeui.generic.fragment.CakeFragment.java
com.cakeui.generic.service.CakePeriodicService.java
com.cakeui.generic.service.CakeService.java
com.cakeui.utils.CakeAsyncTask.java
com.cakeui.utils.CakeBroadcastReceiver.java
com.cakeui.utils.CakeComparator.java
com.cakeui.utils.CakeDataEncapsulation.java
com.cakeui.utils.CakeMap.java
com.cakeui.utils.enums.AsyncTaskType.java
com.cakeui.utils.enums.DialogType.java
com.cakeui.utils.enums.PagesOpen.java