내 활동에 동일한 TextView를 10 회 추가해야합니다.textview를 반복하는 방법은 무엇입니까?
layout.xml에서 textview의 정의를로드하고 프로그래밍 방식으로 반복 할 수 있습니까?
내 활동에 동일한 TextView를 10 회 추가해야합니다.textview를 반복하는 방법은 무엇입니까?
layout.xml에서 textview의 정의를로드하고 프로그래밍 방식으로 반복 할 수 있습니까?
public class YourClassName extends Activity
{
@Override
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
// set activity layout
setContentView(R.layout.some_activity_layout);
LinearLayout mainActivityLayout = (LinearLayout)findViewById(R.id.main_layout);
LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// then see previous answer
// loop n times {
TextView yourTextView = _li.inflate(R.layout.text_view_layout, null);
mainActivityLayout.addView(yourTextView);
// } end loop
}
}
for(int i=0;i<10;i++){
Textview text = new TextView(this);
mainlayout.add(text);
}
이 11 TextViews –
체크 대답 ... 0 10은 9 11.Now 0 (전 <이기 때문에 10) .... –
당신은 재사용 UI 구성 요소에이 글을 읽을 수 있습니다 : http://developer.android.com/resources/articles/layout-tricks-reuse.html
감사합니다 ... 나는이 같은 해결책을 찾고있었습니다. – Webman