Что я сделаю, чтобы добавить этот макет в файл main.xml. этот файл класса отчасти зависит от основного класса активности. должен ли я вызвать этот класс в основной класс активности, чтобы добавить этот динамический tablelayout. и скажите мне, как добавить этот класс в основной класс активностиКак добавить настраиваемый tablelayout в макет .xml?
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
, что я должен сделать, чтобы пройти этот TableLayout в макете main.xml
Большое спасибо :-) его работы, спасибо много –