0

I have a GridView adapter based on some example code that I'm trying to figure out. Basically I have an arraylist of applications that I pass into the adapter, the Applications class, among other things, contains the packageinfo for all apps that have been qualified by the user as "Arcade". What I want is to extract the icons from the packageinfo then blow them up and put them into the GridView, no text or anything else underneath, just the app icons.

public class GridAdapter extends BaseAdapter {
    private Context mContext;
    ArrayList<Applications> mlistArcadeApps;

    public GridAdapter(Context context, ArrayList<Applications> listArcadeApps) {
        this.mlistArcadeApps = listArcadeApps;
        mContext = context;
    }

    public int getCount() {
        return mlistArcadeApps.size();
    }

    public Object getItem(int position) {
        return mlistArcadeApps.get(position);
    }

    public long getItemId(int position) {
        return 0;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = 


    }
}

I have that much so far, I'm not entirely sure if this is even right, I'm just trying to get a hold on how to use GridViews, is it possible to extract app icons as an ImageView object? Or is there an alternative method I should look at?

scibor
  • 983
  • 4
  • 12
  • 21

1 Answers1

0

Yes you are doing it right, you need to create another XML file for each item in the list. Create and XML file and put ImageView inside the LinearLayout. After that you need to pass this xml file to your GridView.

Inside your getView method you can update ImageView and show your icons.

This tutorial explains it clearly : Android GridView Layout Tutorial

I just realized, in this tutorial he doesn't create XML file for each item, instead he creates new ImageView at RunTime.

If you look at this example, it shows in different way : Android GridView Example

Gokhan Arik
  • 2,626
  • 2
  • 24
  • 50
  • Hmm I will mess around with this some more. I feel like all the GridView tutorials are for images but I'm having difficulty extracting the appIcons as images. But thank you for the answer – scibor Jun 25 '13 at 14:49
  • So your question is not about GridView? It is more about getting App icon. Check this answers : [How to get the icon of other applications (Android)](http://stackoverflow.com/questions/2384713/how-to-get-the-icon-of-other-applications-android) - [Getting App Icon in Android](http://stackoverflow.com/questions/4600740/getting-app-icon-in-android/16279240#16279240) – Gokhan Arik Jun 25 '13 at 15:03