Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package voronin.kirill.util;
- import android.widget.BaseAdapter;
- import android.content.Context;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ImageView;
- import android.widget.TextView;
- import android.view.LayoutInflater;
- import android.content.res.Resources;
- import android.view.Menu;
- import android.util.Log;
- public class IconizedMenuAdapter extends BaseAdapter {
- private Context context;
- private Resources res;
- public String[] labels, icons;
- private int menuLabelResource, menuIconResource, inflateView;
- public IconizedMenuAdapter (Context context, int inflateView, int menuLabelResource, int menuIconResource, int labelsResource, int iconsResource) {
- this.context = context;
- this.inflateView = inflateView;
- this.menuLabelResource = menuLabelResource;
- this.menuIconResource = menuIconResource;
- res = context.getResources();
- labels = res.getStringArray(labelsResource);
- icons = res.getStringArray(iconsResource);
- }
- public Object getItem (int position) {
- return position;
- }
- public long getItemId (int position) {
- return position;
- }
- public int getCount () {
- return labels.length;
- }
- public View getView (int position, View convertView, ViewGroup parent) {
- View view = convertView;
- if (view == null) {
- LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = inflater.inflate(inflateView, null);
- }
- TextView label = (TextView) view.findViewById(menuLabelResource);
- ImageView icon = (ImageView) view.findViewById(menuIconResource);
- label.setText(labels[position]);
- if (position < icons.length && icons[position] != "")
- icon.setImageDrawable(
- res.getDrawable(
- res.getIdentifier(icons[position], "drawable", context.getPackageName()
- )));
- return view;
- }
- }
Add Comment
Please, Sign In to add comment