Code example for TableRow

Methods: addView, setGravity, setLayoutParams

0
//	    final TableLayout table = new TableLayout(this); 
//		final TableLayout table = (TableLayout) findViewById(R.id.submenu); 
	     
	    final TableLayout table = (TableLayout) findViewById(R.id.tablelayout);
		table.setStretchAllColumns(true); 
		  TableRow tr1 = new TableRow(this);//(TableRow) findViewById(R.id.row1);//new TableRow(this);
		  tr1.setLayoutParams(new LayoutParams(
                  LayoutParams.FILL_PARENT,
                  LayoutParams.WRAP_CONTENT));
		  tr1.setGravity(Gravity.CENTER);
		  TableRow tr2 = new TableRow(this);//(TableRow) findViewById(R.id.row2);//new TableRow(this);
//		  tr2.setLayoutParams(new LayoutParams( 
//                  LayoutParams.FILL_PARENT, 
//                  LayoutParams.WRAP_CONTENT)); 
		  tr2.setGravity(Gravity.CENTER);
		  TableRow tr3 = new TableRow(this);//(TableRow) findViewById(R.id.row3);//new TableRow(this);
//		  tr3.setLayoutParams(new LayoutParams( 
//                  LayoutParams.FILL_PARENT, 
//                  LayoutParams.WRAP_CONTENT)); 
		  tr3.setGravity(Gravity.CENTER);
		  TableRow tr4 = new TableRow(this);//(TableRow) findViewById(R.id.row4);//new TableRow(this);
//		  tr4.setLayoutParams(new LayoutParams( 
//                  LayoutParams.FILL_PARENT, 
//                  LayoutParams.WRAP_CONTENT)); 
		  tr4.setGravity(Gravity.CENTER);
		  ImageView img1 = new ImageView(this);//(ImageView) findViewById(R.id.image1);//new ImageView(this);
		  ImageView img2 = new ImageView(this);//(ImageView) findViewById(R.id.image2);//new ImageView(this);
		  ImageView img3 = new ImageView(this);//(ImageView) findViewById(R.id.image3);//new ImageView(this);
		  TextView it1 = new TextView(this);//(TextView) findViewById(R.id.text1);//new TextView(this);
		  it1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);  
		  TextView it2 = new TextView(this);//(TextView) findViewById(R.id.text2);//new TextView(this);
		  it1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);  
		  TextView it3 = new TextView(this);//(TextView) findViewById(R.id.text3);//new TextView(this);
		  it1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);  
		  if(alinanposition==2){
			  
			  it1.setText(SocialIcons[0]);
			  it2.setText(SocialIcons[1]);
			  it3.setText(SocialIcons[2]);
			  img1.setImageResource(socialNetwork[0]);
			  img2.setImageResource(socialNetwork[1]);
			  img3.setImageResource(socialNetwork[2]);
		  } 
          if(alinanposition==5){
        	  it1.setText(FolderIcons[0]);
			  it2.setText(FolderIcons[1]);
			  it3.setText(FolderIcons[2]);
			  img1.setImageResource(folder[0]);
			  img2.setImageResource(folder[1]);
			  img3.setImageResource(folder[2]);
		  }	 
          
//		  	it1.setText("ayse"); 
//		  	img1.setImageResource(R.raw.firefox); 
          tr1.addView(img1);
          tr2.addView(it1);
          tr1.addView(img2);          
          tr2.addView(it2);
          tr3.addView(img3);
          tr4.addView(it3);
          table.addView(tr1);
          table.addView(tr2);
Stop searching for code, let great code find you!  Add Codota to your java IDE