OS/Android
Android :: findViewByIdVallistA2014. 7. 27. 21:54
안드로이드 레이아웃에 있는 우리가 뿌려준 오브젝트들을 접근하기 위해서는 어떻게 해야 할까요?
그 접근을 위해서 우리는 먼저, 레이아웃 무엇을 뿌려줄 것인지에 대해 생각을 해봐야 합니다.
자 먼저 기본적인 소스에 대해서 봅시다.
1 2 3 4 5 6 7 8 | public class TestActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_logo); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public class TestActivity extends Activity { private TextView mTitleFont_textview = null ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_logo); mTitleFont_textview = (TextView)findViewById(R.id.titlename); mTitleFont_textview.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf" )); } } |
사용하는 방법은 여기서 mTitleFont_textview. 하고 쓰시면 되겠습니다.
findViewById 앞에 왜 (TextView)를 써주는가 하면, findViewById는 기본적으로 고정된 형을 가지고 있고, 우리는 찾아서 그것을 넣어주어야 하는데,
형이 맞지 않아서 넣어지지 않기 때문입니다.
물론 TextView가 아닌 Button 이라고 할 경우에는 앞에 (Button)을 해주면 될 것 입니다.
'OS > Android' 카테고리의 다른 글
Android :: Sound Pool & Media Player (0) | 2014.06.12 |
---|
VallistA
병특이 끝나서 게임에서 웹으로 스위칭한 프로그래머.
프로그래밍 정보등을 공유합니다.
현재는 이 블로그를 운영하지 않습니다.
vallista.kr 로 와주시면 감사하겠습니다!
자고 싶습니다. ㅠㅠ
Github :: 링크
궁금한점 문의 주시면 답변드리도록 하겠습니다
VISITED
Today :
Total :
Lately Post
Lately Comment