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 6195767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:31:31+00:00 2026-05-24T03:31:31+00:00

Both phone and emulator are 2.2. Trying to create a gridview with a custom

  • 0

Both phone and emulator are 2.2.

Trying to create a gridview with a custom SimpleCursorAdapter class. The gridview contains a image and text view.

The code below works perfectly on the emulator but nothing shows up when I try it on the phone.

I have noticed that only the constructor is called from the phone (not newView or bindView)! Any help?

public class GridAdapter extends SimpleCursorAdapter {
       private Context context; 
       private int mLayout;

       public GridAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
           super(context, layout, c, from, to);

           this.context = context;
           mLayout = layout;

        }

       @Override
       public View newView(Context context, Cursor cursor, ViewGroup parent) {
           Cursor c = getCursor();

           final LayoutInflater inflater = LayoutInflater.from(context);
           View v = inflater.inflate(mLayout, null);

           v.setLayoutParams(new GridView.LayoutParams(150,150));


           return v;

       }

       @Override
       public void bindView(View v, Context context, Cursor c) {

           int nameCol = c.getColumnIndex("show_title");

           String name = c.getString(nameCol);


           TextView tv = (TextView) v.findViewById(R.id.textView1);
           if (name != null) {

               tv.setText(name);
           }

           ImageView iv = (ImageView) v.findViewById(R.id.album_image);
           iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
           iv.setImageResource(R.drawable.icon);
       }

    }

Here is my main xml file:

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/gridview"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>

Here is my view for each grid position:

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"            
  android:id = "@+id/single_item_id"  
  android:layout_width="fill_parent"
 android:layout_height="fill_parent"      
 android:orientation="vertical"
 > 
  <ImageView
  android:id = "@+id/album_image"
  android:adjustViewBounds="true"
  android:layout_width = "fill_parent"             
  android:layout_height="wrap_content"/>

  <TextView 
  android:text="TextView" 
  android:id="@+id/textView1" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content"/>

 </LinearLayout>

And finally here is my onCreate(well some of it):

gridview = (GridView) findViewById(R.id.gridview);
Cursor c = mDbHelper.fetchAllShows();
int[] to = new int[] {R.id.name};
GridAdapter ga = new GridAdapter(this,R.layout.icon,c,new String[] {"show_title"},
            to);
gridview.setAdapter(ga);

(and yes, I know I am doign nothing with the imageview inside of each position yet).

  • 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-24T03:31:32+00:00Added an answer on May 24, 2026 at 3:31 am

    I ended up taking Herrmann’s advice here. I removed the reference to the context and to the cursor. Also renamed the gridview in my layout and changed the appropriate references in my code.

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

Sidebar

Related Questions

i create an android application to support both mobile android phone and galaxy tab,
I've had a few unexplained crashes happening on both the emulator and the phone
When I use the following code in Android 1.6 it displays both phone numbers
http://qt.nokia.com/downloads/ has links to both. I get that Nokia version has phone emulators and
I have two tables, let's call them meetings and phone calls. They both implement
I'm trying to record sound using Android Emulator. I know that this question is
i am attempting to get my android app to work on both phone type
How do I get a Edittext with both a phone input and the ability
I'm recieving the following error when trying to run my app on my phone.
I have made a custom control for windows phone 7. If I use this

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.