Skip to main content

Custom Grid View

This example shows custom Grid View, have a ImageView and TextView in each grid like this: 




1) Create a folder /res/drawable to hold the different pictures.
2) Modify main.xml to have a GridView : 
<?xml version="1.0" encoding="utf-8"?>

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
android:id="@+id/gridView1" 
android:layout_height="fill_parent"
android:horizontalSpacing="5px"
android:verticalSpacing="5px"
android:stretchMode="columnWidth"
android:columnWidth="60px"
android:numColumns="3"
android:gravity="center"
/>
Now,
3)  Implement mygrid.xml in folder /res/layout/, it's the layout of individual grid. 
<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout 
  android:id="@+id/linearLayout1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical">
    
 <ImageView 
     android:layout_height="100px" 
     android:id="@+id/imageView1"
     android:layout_width="100px"
     android:background="#444444"></ImageView>
    
    <TextView 
     android:id="@+id/textView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:gravity="center"
     android:textStyle="bold"
     android:layout_gravity="center"
     android:textColor="#669966"></TextView>    
</LinearLayout>
Next,
4) Modify the main Java code in src/<Packge-Name>/mygridActivity.java.

package com.GridDemo;

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.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class mygridActivity  extends Activity {   

private GridView g;
Integer[ ] img = {
                                        R.drawable.icon_guidelines_logo,
                                        R.drawable.launcher_light,
R.drawable.menu_light,
                                        R.drawable.launcher_structure,
R.drawable.menu_style,
                                        R.drawable.tab_unselected_light,
R.drawable.statusbar_style,
                                        R.drawable.tab_style_unselected,
R.drawable.tab_icon_unselected
                                 };

String[ ] labels = {  "Android", "Calender", "Sweety's Home", 
                                        "New Calender","Home","Star","GTalk","Mick","No Entry"  } ;
/** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        g = (GridView)findViewById(R.id.gridView1);
        g.setAdapter(new ImageAdapter(this));
        
        g.setOnItemClickListener(new OnItemClickListener() {

     public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
     long arg3) {
         
        Toast.makeText(getBaseContext(), "Pic : " +(arg2+1), 1).show();
     }
           } );
        
    }    
    public class ImageAdapter extends BaseAdapter
    {
     Context mGrid;
public ImageAdapter(GridDemo g) {
this.mGrid = g;
}

public int getCount() {
return img.length;
}

public Object getItem(int position) {
return position;
}

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

public View getView(int position, View convertView, ViewGroup parent) {
View view;
if(convertView == null)
{
view = new View(mGrid);
LayoutInflater Inf = getLayoutInflater();
view = Inf.inflate(R.layout.myfile, null);
}
else
{
view = convertView;
}
ImageView iv = (ImageView)view.findViewById(R.id.imageView1);
TextView tv = (TextView) view.findViewById(R.id.textView1);
iv.setImageResource(img[position]);
        tv.setText(labels[position]);
return view;
}    
    }
}

Comments

Popular posts from this blog

Why Domain-Specific AI Agents Beat One Big Agent

Everyone is building agents right now. Real estate firms. Independent insurance brokers. Fortune 500 companies with budgets big enough to hire an army of consultants. Ask around and you'll hear the same story everywhere: "we're building our own agent." And yet almost nobody is asking the obvious question: why does the default approach keep failing? One large, general-purpose agent gets wired up to every tool the business owns. It impresses in the demo. Then it quietly stalls before production. There's a gap between what businesses want and what they're actually getting. They want AI woven into their data, their workflows, their day-to-day operations. What they get instead is one oversized agent trying to be a sales rep, a compliance officer, and a customer support line, all at once. That gap is an architecture problem, not a model problem. Key Takeaways The default "one big agent" pattern breaks down on context bloat, cost, fragility, and portability...

How Create AVD for Samsung Galaxy Tab

1. Open the Android AVD and SDK Manager  2.  Select Available Packages in the left panel of AVD Manager. 3.  Click “Add ADD-on Site” and enter the URL below. http://innovator.samsungmobile.com/android/repository/srepository.xml   4. Check Samsung GALAXY Tab Add-on packages and click install button. 5. Check Samsung GALAXY Tab Add-on license & Click install button. 6) After downloading and installation of GALAXY Tab Add-on, you should restart ADB (Android Debug Bridge) or Eclipse. The important specs of this device, from an Emulator perspective, are: Target platform: Android 2.2, Galaxy Tab Screen Info: High Density, despite the fact that it’s not, this is what it reports, WSVGA (1024×600) No keyboard Has dual cameras Let’s create an AVD configuration called GalaxyTab: Within Eclipse, launch the Android SDK and AVD Manager Select “Virtual Devices” from the left-hand options Click the “New” button to create a new AVD configura...

Don't Ship AI Agent Skills Without Evals

At the AI Engineer World's Fair on July 1, 2026, Philipp Schmid, a Staff Engineer on the Gemini API and agents team at Google DeepMind, asked a room full of engineers a simple question: who uses skills with their coding agents? Every hand went up. Who has evals for those skills? Almost none. That gap is the entire talk, which Schmid also wrote up on his own blog, philschmid.de/testing-skills . His team indexed the skills ecosystem through SkillsBench and found the same pattern everywhere: people ship a SKILL.md file after two manual test runs and move on. It looks fine in a demo. It quietly corrupts outputs in production, because bad skills don't crash. They just make the agent confidently wrong. If you've already read our breakdown of Matt Pocock's Claude Code skills library , think of this as the other half of that story: what happens once you've installed a skill and it's actually running against real prompts. Key Takeaways SkillsBench indexed 47,000+ un...