title: How to give border of cells in tablelayout in android
body: <p>I have a question that how to give cell borders in tablelayout of Android programmatically.</p>
  
  <p><strong>Here is my Code:</strong></p>
  
  <pre><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 &lt; size-2; i+=3)
           {
           row = new TableRow(SearchGridActivity.this);
           row.setId(100+i);
  
           for(j=0;j&lt;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);
  </code></pre>