안드로이드 개발 질문/답변
(글 수 45,052)
ViewPager로 2개의 Layout을 불러내서
2page로 된 화면을 만들었습니다.
public Object instantiateItem(View pager, int position) {
View v = null;
if (position == 0) {
v = mInflater.inflate(R.layout.main, null);
int btnid = R.id.main_btn_01;
for (int i = 0; i < BTN_COUNT; i++) {
v.findViewById(btnid + i)
.setOnClickListener(mClickListener);
}
}
else if (position == 1) {
v = mInflater.inflate(R.layout.main_2, null);
}
((ViewPager) pager).addView(v, 0);
return v;
}
여기서 질문입니다.
main_2.xml에 있는 TextView에 Java 소스로 setText 할 수 있는 방법이 있을까요?
position == 1일때
v = mInflater.inflate(R.layout.main_2, null);TextView tv = (TextView)findViewById(R.id.text);
tv.setText("텍스트");
이렇게 소스를 짜니까 에러가 납니다;
ViewPager를 전개할때 텍스트를 쓰는 방법 없을까요?
엄청난 삽질 결과 해답을 찾았네요
v = mInflater.inflate(R.layout.main_2, null);
TextView tv = (TextView)v.findViewById(R.id.text);
tv.setText("텍스트");
레이아웃에 있는 위젯 찾기전에 (findViewById 앞에) view 객체 (v)를 넣어주니까
에러 안나고 수정이 가능하더군요..
참고하셔여~