what will i do to add this layout into main.xml . this class file is sperate from main activity class. should i need to call this class into main activity class for add this dynamic tablelayout. and tell me how to add this class into main activity class
import android.R.color;
import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.SimpleAdapter.ViewBinder;
import android.widget.TableRow.LayoutParams;
public class TestGridActivity extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
TableLayout layout = new TableLayout (this);
layout.setLayoutParams( new TableLayout.LayoutParams(85,85) );
layout.setPadding(8,8,8,8);
for (int f=0; f<=6; f++) {
TableRow tr = new TableRow(this);
tr.setBackgroundColor(Color.BLACK);
tr.setPadding(0,0, 0,2 );
TableRow.LayoutParams llp = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
llp.setMargins(0, 0, 2, 0);//2px right-margin
//New Cell
for (int c=0; c<=288; c++) {
LinearLayout cell = new LinearLayout(this);
cell.setBackgroundColor(Color.WHITE);
cell.setLayoutParams(llp);//2px border on the right for the cell
TextView b = new TextView (this);
b.setText("Sample");
b.setTextSize(10.0f);
b.setHeight(60);
b.setWidth(70);
b.setPadding(0, 0, 4, 0);
cell.addView(b);
tr.addView(cell);
} // for
layout.addView(tr);
} // for
super.setContentView(layout);
} // ()
public void onClick(View view) {
((TextView) view).setText("*");
((TextView) view).setEnabled(false);
}
} // class
what should i do to pass this tablelayout into main.xml layout
so your code for onCreate() will be like the following