Android GridMenu layout - images not showing up

I am creating a simple app for my own use. I want to have a simple menu using GridLayout, using arrays and ArrayAdapter.

Here is my java code:

package com.jlo.love;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class Love extends Activity implements OnItemClickListener{
    /** Called when the activity is first created. */

    GridView menu;
    private String[] menu_text = {
    "Location",
    "Rotate",
    "Gallery",
    "View",
    "My Places",
    "Search"};

    Integer[] menu_icon = {
            android.R.drawable.ic_menu_mylocation,
            android.R.drawable.ic_menu_rotate,
            android.R.drawable.ic_menu_gallery,
            android.R.drawable.ic_menu_view,
            android.R.drawable.ic_menu_myplaces,
            android.R.drawable.ic_menu_search};


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);

        menu = (GridView)findViewById(R.id.Menu);
        menu.setOnItemClickListener(Love.this);
        menu.setAdapter(new MenuItem(Love.this, R.layout.menu_item, menu_text));




    }
    public class MenuItem extends ArrayAdapter<String> {

        public MenuItem(Context context, int textViewResourceId, String[] objects) {

        super(context, textViewResourceId, objects);

        }

}
    public View getView(int position, View convertView, ViewGroup parent) {

        LayoutInflater inflater=getLayoutInflater();
        View row=inflater.inflate(R.layout.menu_item, parent, false);
        TextView tv=(TextView)row.findViewById(R.id.text);
        ImageView iv = (ImageView)row.findViewById(R.id.Menu);

        tv.setText(menu_text[position]);
        iv.setImageResource(menu_icon[position]);
        return row;

        }



    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub

    }


}//end class

these are my XMLs

menu_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|top"
android:maxLines="2"
android:textColor="#000"
android:drawablePadding="5dp"
android:minLines="2"
android:background="@null">
</TextView>

My second XML - menu.xml

<?xml version="1.0" encoding="utf-8"?>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="25dp"
android:horizontalSpacing="10dp"
android:columnWidth="70dp"
android:background="#ffffff"
android:stretchMode="columnWidth"
android:gravity="center_horizontal|top"
android:scrollbars="none"
android:paddingTop="10dp">
</GridView>

I have the 6 icons, on all the 3 drawable folders.

When i launch it on the simulator, this is what i have-

the text shows up, but no images icon show up.

Screenshot

Could anyone point me in the right direction..

Answers


If I understood everything correctly you wan some icons to appear with the text that is showing in the grid view. But I noticed that your menu item xml does not have an image view, you should be getting a NULLPOINTER EXCEPTION, have you posted the correct xml/java ?


Need Your Help

writing to JEditorPane fast

java multithreading swing jeditorpane invokelater

In the code below I would like to write onto JEditorPane the numbers 0 to 10000. However, the JEditorPane does not display anything unless either it is completely done ( printing all 0 to 10000 at ...

Unreachable code detected WP8

c# windows-phone-8 return messagebox

This code will not continue if the IsDownloaded is True. How do I properly have a MessageBox pop if if False and Return;? If I take out the 'Return;' RingToneTask never occurs even if IsDownloade...