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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:04:51+00:00 2026-05-24T18:04:51+00:00

I have a question that how to give cell borders in tablelayout of Android

  • 0

I have a question that how to give cell borders in tablelayout of Android programmatically.

Here is my Code:

 TableLayout table = (TableLayout)findViewById(R.id.linear_Layout_List);
         TableRow row=null;
         TableRow row1=null;
         Button label = null;

         int size=items.size();
         for (int i = 0; i < size-2; i+=3)
         {
         row = new TableRow(SearchGridActivity.this);
         row.setId(100+i);

         for(j=0;j<3;j++)
         {
            /*TableLayout.LayoutParams tableRowParams=
                  new TableLayout.LayoutParams
                  (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
            int leftMargin=10;
            int topMargin=2;
            int rightMargin=10;
            int bottomMargin=2;

            tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);

            row.setLayoutParams(tableRowParams);*/
            if(count_img!=NUM_RESULTS)
            {
            //row.setPadding(10, 2, 10, 0);

            View v = View.inflate(this, R.layout.tablecell, null);
            LinearLayout lay = (LinearLayout)v.findViewById(R.id.linear_table);
            /*MarginLayoutParams layoutParams = new MarginLayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

                layoutParams.setMargins(30, 20, 30, 0);*/

            final ImageView img = new ImageView(this);

            img.setImageBitmap(imageBitmap[count_img]);
            img.setClickable(true);
            img.setId(count_img);

            img.setOnClickListener(new View.OnClickListener() {


                    public void onClick(View arg0) {

                         BaseInventoryItem item = items.get(img.getId());
                            if (item instanceof Offer) {

                                SearchResultActivity.list_flag = false;
                                grid_flag = true;

                                Intent intent = new Intent(SearchGridActivity.this, ProductComparisonActivity.class);
                                intent.putExtra("item", item);
                                startActivity(intent);

                            } else if (item instanceof Product) {

                                SearchResultActivity.list_flag = false;
                                grid_flag = true;

                                Intent intent = new Intent(SearchGridActivity.this, ProductComparisonActivity.class);
                                intent.putExtra("item", item);
                                startActivity(intent);
                            }
                    }

                });
             BaseInventoryItem item = items.get(count_img);

             TextView txt_price = new TextView(this);

              if (item instanceof Offer) {
                  Offer offer = (Offer) item;
                  txt_price.setText(offer.getPrice().getPrice());
                  txt_price.setTextColor(Color.BLACK);
                  txt_price.setTextSize(15);
              } else if (item instanceof Product) {
                  Product product = (Product) item;
                  txt_price.setText("from " + product.getPriceSet().getMinPrice().getPrice());
                  txt_price.setTextColor(Color.BLACK);
                  txt_price.setTextSize(15);
              }



            lay.addView(img);
            lay.addView(txt_price);
            row.addView(v);
            count_img++;
            }
         }
         //row.addView(label);

         table.addView(row);


         }
        /* row1 = new TableRow(SearchGridActivity.this);
         row1.setId(10001);*/
         TableRow row2 = (TableRow) View.inflate(this, R.layout.tablerow, null);
         Button btn_load = (Button)row2.findViewById(R.id.btn_table_LoadMore);
         btn_load.setOnClickListener(new View.OnClickListener() {


                public void onClick(View arg0) {

                    NUM_RESULTS = NUM_RESULTS+12;
                    Intent intent = new Intent(SearchGridActivity.this,SearchGridActivity.class);
                    intent.putExtra("keyword", keyword);
                    startActivity(intent);
                }
            });
        /* row1.setLayoutParams(new LayoutParams(
         LayoutParams.FILL_PARENT,
         LayoutParams.FILL_PARENT));*/
         TableRow.LayoutParams rowSpanLayout = new TableRow.LayoutParams(
                 TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT);
         rowSpanLayout.span = 3;


         //row.setBackgroundColor(0xff222222);

        label = new Button(SearchGridActivity.this);
        label.setText("Load More");


        //label.setBackgroundColor(Color.BLUE);


         //row1.addView(label);

         //row.addView(label);

         table.addView(row2,rowSpanLayout);
  • 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-24T18:04:52+00:00Added an answer on May 24, 2026 at 6:04 pm

    there is no direct way of doing this. you have to mess around with background, margins and padding.

    i ended up using something like this

    <TableLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:stretchColumns="*" android:background="#ff0000">
    <TableRow android:background="#00ff00" android:layout_margin="2dip">
        <Button android:id="@+id/button" android:text="+" android:background="#0000ff" android:layout_margin="2dip"/>
        <TextView android:text="@string/label"  android:background="#0000ff" android:layout_margin="2dip"/>
        <TextView android:id="@+id/amount"  android:background="#0000ff" android:layout_margin="2dip"/>
    </TableRow>
    

    taken from here. LINK

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

Sidebar

Related Questions

That's the question. Give only one reason you think why have OODB failed or
First time I'm writing something here. I have a question that i hope someone
Question: I have a question that is apparently not answered by this already-asked Bash
I have a question that may be quite naive, but I feel the need
I have a question that I just don't feel like I've found a satisfactory
I have a question that I'm ashamed to ask, but I'm going to have
I have a question that may sound odd, but being somewhat of a newbie,
I have a question that can I use AS400ConnectionPool in Spring if then pls
I have a question that's somewhat of an extension of this thread . I
I have a simple question that I am posing mostly for my curiousity. What

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.