1.Reosurce
- 리소스는 이미지파일, XML파일 등을 의미함
- 리소스를 코드 내로 불러오기 위해서는 리소스ID를 사용한다. ex) R.layout.activity_quiz
- layout에는 id가 자동 생성되지만 widget은 별도로 id를 지정해주어야한다.
- widget에 대한 참조변수 만들기 : mTrueButton=(Button) findViewById(R.id.true_button);
- 리스너 :
1 2 3 4 5 6 | mTrueButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(QuizActivity.this,
R.string.correct_toast,
Toast.LENGTH_SHORT).show(); } }); | cs |
2.
1 2 3 4 5 6 7 8 9 | <Button android:id="@+id/false_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/false_button" /> | cs |
@+id에는 + 기호가 있지만 @string 에는 기호가 없는 이유 : id는 새로 추가하는 것이지만 string은 string.xml에 저장된 값을 참조하는것이기 떄문이다.
'Web Programming > Android' 카테고리의 다른 글
7. UI Fragments and the Fragment Manager (0) | 2018.08.20 |
---|---|
5. Your Second Activity (0) | 2018.08.16 |
3. The Activity Lifecycle (0) | 2018.08.14 |
2. Android and Model-ViewController (0) | 2018.08.14 |