// programmatically creating grid on run time
int z=0;
if(Integer.valueOf(sing.questionsObjectArr[index].noOfcolumns) > Integer.valueOf(
sing.questionsObjectArr[index].noOfrows)){
while(z < Integer.valueOf(sing.questionsObjectArr[index].noOfcolumns)){
gridEdittext.add(new ArrayList<TextView>());
z++;
}
}
else{
while(z < Integer.valueOf(sing.questionsObjectArr[index].noOfrows)){
gridEdittext.add(new ArrayList<TextView>());
z++;
}
}
for(int x = 0; x < Integer.valueOf(sing.questionsObjectArr[index].noOfrows); x++){
this.ll = new LinearLayout(this);
this.ll.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
this.ll.setOrientation(0);
for(int y = 0; y < Integer.valueOf(sing.questionsObjectArr[index].noOfcolumns); y++){
if(y==0){
this.gridEdittext.get(y).add(new TextView(this));
this.gridEdittext.get(y).get(x).setId(y);
this.gridEdittext.get(y).get(x).setTextColor(Color.BLACK);
if(x!=0){
this.gridEdittext.get(y).get(x).setText(
sing.questionsObjectArr[index].columnData.get(x-1).toString());
}
else{
this.gridEdittext.get(y).get(x).setText(
sing.questionsObjectArr[index].rowData.get(x).toString());
}
LinearLayout.LayoutParams colparams = new LinearLayout.LayoutParams(60, 60);
colparams.setMargins(20, 0, 20, 0);
this.gridEdittext.get(y).get(x).setLayoutParams(colparams);
this.ll.addView(this.gridEdittext.get(y).get(x));
y++;
}
if(x==0){
this.gridEdittext.get(y).add(new TextView(this));
this.gridEdittext.get(y).get(x).setTextColor(Color.BLACK);
this.gridEdittext.get(y).get(x).setId(y);
this.gridEdittext.get(y).get(x).setText(
sing.questionsObjectArr[index].rowData.get(y).toString());
LinearLayout.LayoutParams colparam = new LinearLayout.LayoutParams(60, 60);
colparam.setMargins(0, 0, 20, 0);
this.gridEdittext.get(y).get(x).setLayoutParams(colparam);
this.ll.addView(this.gridEdittext.get(y).get(x));
}
else{
this.gridEdittext.get(y).add(new EditText(this));
this.gridEdittext.get(y).get(x).setId(y);
this.gridEdittext.get(y).get(x).setText("");
this.gridEdittext.get(y).get(x).setLayoutParams(new LinearLayout.LayoutParams(80, 80));
this.ll.addView(this.gridEdittext.get(y).get(x));
}
}
tlayout.addView(this.ll);
tlayout.setBackgroundResource(R.drawable.roundshape);
}
我正在创建动态网格,EditText
其中包含可以接受数据的表格,表格被 TextView 包围。问题是 TextView 的文本在 Android 2.3 中完美显示,但在 Android 4.0 中却没有。