Android Open Source - Android-Lib-ContextMenu Menu Item Adapter






From Project

Back to project page Android-Lib-ContextMenu.

License

The source code is released under:

Apache License

If you think the Android project Android-Lib-ContextMenu 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 android.lib.contextmenu;
/*ww w . j a v  a 2s  .c o m*/
import android.content.Context;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

final class MenuItemAdapter extends BaseAdapter {
    private final Context context;
    private final Menu    menu;

    public MenuItemAdapter(final Context context, final Menu menu) {
        this.context = context;
        this.menu    = menu;
    }

    @Override
    public int getCount() {
        return this.menu.size();
    }

    @Override
    public Object getItem(final int position) {
        return this.menu.getItem(position);
    }

    @Override
    public long getItemId(final int position) {
        return this.menu.getItem(position).getItemId();
    }

    @Override
    public View getView(final int position, final View convertView, final ViewGroup parent) {
        final MenuItem   item = this.menu.getItem(position);
        final View       view;
        final ViewHolder holder;

        if (convertView == null) {
            view   = View.inflate(this.context, R.layout.popup_menu_item, null);
            holder = new ViewHolder((ImageView)view.findViewById(R.id.popup_icon), (TextView)view.findViewById(R.id.popup_title));

            view.setTag(holder);
        } else {
            view   = convertView;
            holder = (ViewHolder)view.getTag();
        }

        holder.icon.setImageDrawable(item.getIcon());
        holder.title.setText(item.getTitle());

        return view;
    }

    private final class ViewHolder {
        public ImageView icon;
        public TextView  title;

        public ViewHolder(final ImageView icon, final TextView title) {
            this.icon  = icon;
            this.title = title;
        }
    }
}




Java Source Code List

android.lib.contextmenu.ContextMenu.java
android.lib.contextmenu.MenuItemAdapter.java
android.lib.contextmenu.MockMenuItem.java
android.lib.contextmenu.MockMenu.java