Gonzalo Ortellado
Gonzalo Ortellado

Reputation: 583

Use android-iconics within an adapter

I'm new to android so this is probably very easy to clarify.

I want to use fontawesome icons in my app. For that purpose, I'm trying to use this library

https://github.com/mikepenz/Android-Iconics

This is my question:

I have gridview that is filled with an adapter. This is the adapter's getView method:

@Override
public View getView(int p, View convertView, ViewGroup parent) {
View grid;
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ImageView imageView;

    if (convertView == null) {
        grid = new View(mContext);
        /*LLENO EL GRID CON EL CUSTOM*/
        grid = inflater.inflate(R.layout.gridview_custom_layout, null);

        /*AGREGO EL TEXTO AL GRID VIEW*/
        TextView textView = (TextView) grid.findViewById(R.id.gridview_text);
        textView.setText(string[p]);


        imageView = (ImageView)grid.findViewById(R.id.gridview_image);
        /*THIS IS HOW I SET THE DRAWABLE*/
        //imageView.setImageResource(Imageid[p]);

        /*THIS IS HOW I WANT TO USE ICONICS*/
        imageView.setImageResource(new IconicsDrawable(this).icon(FontAwesome.Icon.faw_android).color(Color.RED).sizeDp(24));
        imageView.setTag(String.valueOf(p));

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int pos=Integer.parseInt(view.getTag().toString());
                Toast.makeText(mContext, "GridView Item: " + String.valueOf(pos), Toast.LENGTH_LONG).show();
            }
        });

    } else {
        grid = (View) convertView;
    }

    return grid;
}`

Any ideas?

Upvotes: 1

Views: 513

Answers (1)

Gonzalo Ortellado
Gonzalo Ortellado

Reputation: 583

I found my mistake:

/I added: IconicsDrawable(this.mContext)/

imageView.setImageDrawable(new IconicsDrawable(this.mContext).icon(FontAwesome.Icon.faw_android).color(Color.RED))

Thats is all!

Upvotes: 0

Related Questions