1
프로그래밍 방식으로 layout.xml 파일의 id를 View.inflate 메소드로 전달하려고 시도하지만 어떻게 할 수 있는지 잘 모르겠습니다. 테스트 할 비트가 있습니다. 작업하기 위해 tring을 사용하고 있습니다.이 문자열을 String으로 전달하려고 시도했지만 작동하지 않습니다.안드로이드가 동적으로 View.inflate에 R.layout.extra_layout을 전달합니다.
아이디어가 있으십니까? 고마워.
LinearLayout main = (LinearLayout) findViewById(R.id.mainLayout);
for (int i = 0; i < 3; i++) {
String boxToInflate="R.layout.box"+Integer.toString(i);
LinearLayout ll = (LinearLayout) View.inflate(MainActivity.this, boxToInflate, null);
main.addView(ll);
}
편집 : 몇 분 후. 그냥 교체 또한 드로어 블과 같은 다른 것들에 대한 작동
// Get outer relative layout
LinearLayout main = (LinearLayout) findViewById(R.id.mainLayout);
for (int i = 0; i < 3; i++) {
// String boxToInflate="R.layout.box"+Integer.toString(i);
int resID = getResources().getIdentifier("box" + i, "id",
getPackageName());
LinearLayout ll = (LinearLayout) View.inflate(MainActivity.this,
resID, null);
main.addView(ll);
}
감사합니다. Stephane에게 감사드립니다. - 나는 이드가 레이아웃으로 변경해야한다는 것을 발견했습니다. –
작동하는 경우 내 대답을 수락 된 것으로 표시해야합니다. –
죄송합니다. Stephane, 지금 해결되었습니다. –