我是android.Please的新手,告诉我如何创建一个10行6列的网格,每个单元格都填充了文本视图。我想通过单击一个按钮,用不同的值填充每个单元格的文本。我使用表格布局制作了一个网格,有10行和60个文本视图,但我认为这不是正确的方法。请为我提供这方面的源代码。感谢advance...my中的java file..and xml文件在这里...
TableLayout t1 =(TableLayout)findViewById(R.id.myTableLayout)
// TableRow [] tr = new TableRow[10];
TableRow tr = new TableRow(this);
TextView [] tv = new TextView[20];
int j=0;
int k=0;
//for inserting 10 rows..
for(int i=0;i<=10;i++)
{
String cnt;
tv[j] = new TextView(this);
TextView tv1 = new TextView(this);
TextView ttv = new TextView(this);
// TextView tv = new TextView(this);
//to put a space between cells
//tv1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
tv1.setPadding(20, 0, 0, 0);
tv1.setWidth(30);
tv1.setHeight(45);
tv1.setText("");
//to put digits in text views...
//ttv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
ttv.setPadding(20, 0, 0, 0);
ttv.setWidth(60);
ttv.setHeight(45);
ttv.setTextColor(Color.DKGRAY);
ttv.setBackgroundColor(Color.CYAN);
ttv.setTextSize(25);
cnt=""+k+"";
ttv.setText(cnt);
k++;
// to put symbols store in an array using a button click...the code of button and array in dnt show here...
// tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
tv[j].setPadding(20, 0, 0, 0);
tv[j].setWidth(60);
tv[j].setHeight(45);
tv[j].setTextColor(Color.YELLOW);
tv[j].setBackgroundColor(Color.GREEN);
tv[j].setTextSize(25);
//tv[j].setText("ab");
tr.setPadding(0, 1, 0, 1);
tr.addView(tv1);
tr.addView(ttv);
tr.addView(tv[j]);
j++;
tr.addView(tv1);
tr.addView(ttv);
tr.addView(tv[j]);
j++;
tr.addView(tv1);
tr.addView(ttv);
tr.addView(tv[j]);
t1.addView(tr);
} 发布于 2012-03-28 13:45:59
你不会得到codez的。所以不要自找麻烦。我很早就学会了,所以建议你试着自己编码。只有当我们看到您自己确实做了一些事情时,我们才会提供帮助。
无论如何,使用GridLayout会更好。在布局和按钮的onClick()中包含TextView只需更改相应TextViews的文本,如下所示-
tv1.setText("1st changed");
tv2.setText("2nd changed");诸若此类。
当然你需要找到tv1和tv2。还有。
TextView tv1=(TextView) findViewById(R.id.tv1);发布于 2012-03-28 13:44:51
在XML for gridview中再设置一个属性
android:numColumns="6"用于设置一行中的6列。
然后使用set adapter with length of 60 element,您将获得10X6网格
https://stackoverflow.com/questions/9901681
复制相似问题