Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6992695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:40:05+00:00 2026-05-27T19:40:05+00:00

Right now to populate my GridViews I’m using a extended BaseAdapter class on each

  • 0

Right now to populate my GridViews I’m using a extended BaseAdapter class on each of my Android Activities (which are most of them).

In order to make it easier to read and maintain, I`m trying to put all the BaseAdapter code in a separate class file.

To populate the GridView, I’m using LayoutInflater, and here is where stuff gets tricky…

Since the getLayoutInflater() comes from android.Activity, it just won’t do the trick. I tried making my Adapter.java(the class to populate the GridViews) a extended Activity class, and then inside create the BaseAdapter class (the way I do it right now), but I haven’t been able to make it work properly.

Here’s how Adapter.java looks:

//Adapter.java
package com.cimp.matitec;

import greendroid.app.GDActivity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Adapter extends GDActivity{

public class ImageAdapter extends BaseAdapter
{
   Context MyContext;
   int count;
   String[] nombre;

   public ImageAdapter(Context _MyContext, int n, String[] nombre)
   {
      MyContext = _MyContext;
      count = n;
      this.nombre = nombre;
   }

   public int getCount()
   {
                     /* Set the number of element we want on the grid */
      return count;
   }

   @Override
   public View getView(int position, View convertView, ViewGroup parent)
   {
      View MyView = convertView;

      if ( convertView == null )
      {
         /*we define the view that will display on the grid*/

         //Inflate the layout
         LayoutInflater li = getLayoutInflater();
         MyView = li.inflate(R.layout.grid_item, null);

         // Add The Text!!!
         TextView tv = (TextView)MyView.findViewById(R.id.grid_item_text);
         tv.setText(nombre[position]+"");

         // Add The Image!!!           
         ImageView iv = (ImageView)MyView.findViewById(R.id.grid_item_image);
         iv.setImageResource(R.drawable.ic_launcher);
      }

      return MyView;
   }

   @Override
   public Object getItem(int arg0) {
      // TODO Auto-generated method stub
      return null;
   }

   @Override
   public long getItemId(int arg0) {
      // TODO Auto-generated method stub
      return 0;
   }
}
}

To call it from the outside, I do the following:

//MainClass.java
Adapter MyGridAdapter = new Adapter();
MyGrid = (GridView)findViewById(R.id.grid);
MyGrid.setAdapter(MyGridAdapter.new ImageAdapter(this, 6, nombreTema));

The app runs, but when trying to populate, I got a NullPointerException getLayoutInflater().

Someone knows what I’m missing, or how to make it work properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:40:06+00:00Added an answer on May 27, 2026 at 7:40 pm

    There are more ways to get a LayoutInflater object than directly from an Activity. As a matter of fact, getLayoutInflater() is probably just a convenience method for this:

    LayoutInflater li = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    

    Please see the documentation for LayoutInflater.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as
Right now, I am using the RESTful Authentication framework for authorizations with my rails
I'm using Visual Studio 2005 for a project I'm working on right now. I've
Right now I am using a ASP.NET TreeView with checkboxes enabled in my page,
I'm developing a Java webapp using Spring, Spring Security, Tomcat and MySQL. Right now
Right now, I keep all of my projects on my laptop. I'm thinking that
Right now, I'm particularly interested in reading the data from MP3 files (ID3 tags?),
Right now my ant task looks like. <javadoc sourcepath=${source} destdir=${doc}> <link href=http://java.sun.com/j2se/1.5.0/docs/api/ /> </javadoc>
Right now I'm doing something like this: RewriteRule ^/?logout(/)?$ logout.php RewriteRule ^/?config(/)?$ config.php I
Right now I have an SSIS package that runs every morning and gives me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.