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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:36:56+00:00 2026-06-14T18:36:56+00:00

I would like to implement a gridview within Android, which will basically consist of

  • 0

I would like to implement a gridview within Android, which will basically consist of 4 columns (it will be actiing similary to a table).

This will essentially be a list of items spread across 4 columns (name, qty, p1, p2). So each row contains 4 columns is unique to 1 items. Therefore, I need a way to bind these 4 columns together so that when i select anywhere within those 4 columns the whole row will be selected, whilst returning the ‘name’ column as the text id.

Is there an easy way that this can be done? This is my current code for the gridView:

XML Layout:

<GridView
    android:id="@+id/gvShopCompleteList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/spnShopCharacters"
    android:layout_above="@+id/linerBuyBtns"
    android:numColumns="1"
    android:fastScrollEnabled="true"
    android:scrollbarStyle="insideOverlay">
</GridView>

Binding of Dynamic content:

GridView gridview;
static final String[] listItems = new String[] { "name","qty","p1","p2","itemname","5","100","1" };
gridview = (GridView)findViewById(R.id.gvShopCompleteList);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
gridview.setAdapter(adapter);

gridview.setOnItemClickListener(new OnItemClickListener() 
{
    public void onItemClick(AdapterView<?> parent, View v,int position, long id) 
    {
        Toast.makeText(getApplicationContext(),
        ((TextView) v).getText(), Toast.LENGTH_SHORT).show();
    }
});

Finally, an additional feature I would like to add is to make the header read only and highlighted a different color to the other rows. Any help would be much appreciated here, I do not have to use GridView, but would like to keep the generic android look as much as possible (consistant throughout my app). Thanks.

  • 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-06-14T18:36:58+00:00Added an answer on June 14, 2026 at 6:36 pm

    I’ve made a little sample. Below is the layout file for the row, R.layout.adapters_tablelikelistview:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
    
        <TextView
            android:id="@+id/data1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1" />
    
        <TextView
            android:id="@+id/data2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1" />
    
        <TextView
            android:id="@+id/data3"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1" />
    
        <TextView
            android:id="@+id/data4"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1" />
    
    </LinearLayout>
    

    and the Activity and adapter where the layout above is used:

    public class TableLikeListView extends ListActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);     
            String[] data1 = new String[] { "Header1", "data1", "data2" };
            String[] data2 = new String[] { "Header2", "data1", "data2" };
            String[] data3 = new String[] { "Header3", "data1", "data2" };
            String[] data4 = new String[] { "Header4", "data1", "data2" };
            setListAdapter(new MyAdapter(this, R.layout.adapters_tablelikelistview,
                    R.id.data1, data1, data2, data3, data4));
        }
    
        private static class MyAdapter extends ArrayAdapter<String> {
    
            private String[] data1, data2, data3, data4;
    
            public MyAdapter(Context context, int resource, int textViewResourceId,
                    String[] data1, String[] data2, String[] data3, String[] data4) {
                super(context, resource, textViewResourceId, data1);
                this.data1 = data1;
                this.data2 = data2;
                this.data3 = data3;
                this.data4 = data4;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View v = super.getView(position, convertView, parent);
                if (position == 0) {
                    // header
                    v.setBackgroundColor(Color.GREEN);
                } else {
                    v.setBackgroundResource(android.R.drawable.list_selector_background);
                }
                TextView t1 = (TextView) v.findViewById(R.id.data1);
                t1.setText(data1[position]);
                TextView t2 = (TextView) v.findViewById(R.id.data2);
                t2.setText(data2[position]);
                TextView t3 = (TextView) v.findViewById(R.id.data3);
                t3.setText(data3[position]);
                TextView t4 = (TextView) v.findViewById(R.id.data4);
                t4.setText(data4[position]);
                return v;
            }
    
            @Override
            public boolean isEnabled(int position) {        
                return position == 0 ? false : true;
            }       
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to implement an algorithm which will find the bounding rectangles of
Basically, I would like to implement a GridView wherein the items themselves are clickable,
I would like to implement a switch button, android.widget.Switch (available from API v.14). <Switch
I would like to implement a simple AR desktop application. This application should first
I would like to implement a map simmilar to this: http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/examples/advanced_example.html One of the
I would like implement next sceario: I've got a wi-fi router, which can be
I would like to implement a method like this: boost::unique_future<int> foo() { return defer([=]
I would like to implement a save feature, which allows my users to save
I would like to implement custom sorting on a custom databound GridView. OnSorting has
I would like to implement a grid view of pixmaps. This is how I

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.