안드로이드 개발 질문/답변
(글 수 45,052)
TextView[] tv = new TextView[10];
for(int i=0; i<10; i++)
{
tv[i] = new TextView(this);
tv[i].setText("sdf");
}
위와 같은 형식으로 코드를 작성한후에..
for 문으로 n갯수만큼 텍스트뷰를 표시할려고 하는데
뷰가 화면에 표시가 안되서 그러는데요
방법좀 없을까요..????/
2011.06.13 17:00:22
TextView를 나타낼 레이아웃 등록하셨나요? TextView를 등록하셔야해요~
프로젝트에 res/layout가시면 사용하실 xml파일이 있는데 거기다가
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="유효시간설정"
/>
이런식으로 등록해줘야 Activity에 나타납니다~
만약 10개라면 10개를 등록해줘야하죠...
2011.06.13 19:00:05
public class AtestTextActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll =new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
int lHeight= LinearLayout.LayoutParams.WRAP_CONTENT;
int lWidth= LinearLayout.LayoutParams.WRAP_CONTENT;
TextView[] tv = new TextView[10];
for(int i=0; i<10; i++)
{
tv[i] = new TextView(this);
//tv[i].setWidth(200);
//tv[i].setHeight(45);
tv[i].setText("sdf");
ll.addView(tv[i], new LinearLayout.LayoutParams(lHeight,lWidth));
}
setContentView(ll);
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll =new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
int lHeight= LinearLayout.LayoutParams.WRAP_CONTENT;
int lWidth= LinearLayout.LayoutParams.WRAP_CONTENT;
TextView[] tv = new TextView[10];
for(int i=0; i<10; i++)
{
tv[i] = new TextView(this);
//tv[i].setWidth(200);
//tv[i].setHeight(45);
tv[i].setText("sdf");
ll.addView(tv[i], new LinearLayout.LayoutParams(lHeight,lWidth));
}
setContentView(ll);
}
}




text를 출력할 레이아웃이 없네요..