Spredzy
Spredzy

Reputation: 5164

GridView with customs view

I don't know if it is possible, but actually I wouldn't see why not.

Can we do a grid view not just with ImageView but with a custom view.

I am trying to make a grid view of a view composed of an ImageView and a TextView.

I know that everything happens in my Adapter getView's function but I can't figure out how to do it.

public View getView(int position, View convertView, ViewGroup parent) {
    View cases = findViewById(R.id.fileUnitLayout);

    if (convertView == null) {
       convertView = new View(mContext);
    } else {
       cases = convertView;
    }

       return cases;
    }

My view has an id of R.id.fileUnitLayout. Let's say my inner TextView has an id of A and my inner ImageView has an id of B. How can I fill them ?

Thank you,

Upvotes: 0

Views: 1095

Answers (1)

Cheryl Simon
Cheryl Simon

Reputation: 46844

You should not need to override getView to accomplish this, necessarily. GridView is an AdapterView so you can provide an adapter that will display what you want via setAdapter

You could, for example, use SimpleAdapter to provide an xml file that is used for each grid view item.

Upvotes: 2

Related Questions