안슈 3강/for 문 활용1

버튼 누르면 "ㅋㅋㅋ" 100번 출력

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">  //수직정렬
 
 
    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
 
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">  //스크롤 가능하도록 스크롤 뷰 안에 담기
 
     
 
         <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
      
    </ScrollView>
 
</LinearLayout>
 
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.example.myapplication04;
 
 
 
public class MainActivity extends AppCompatActivity {
 
    TextView textView; //textView변수는 텍스트 뷰 타입이다.  선언
    Button button;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        textView = (TextView) findViewById(R.id.textView);
//textView변수에 담아라= 아이디를 찾아서(리소스에 아이디가 textView인)
//즉, xml파일에서 textView 아이디 가진 애를 가져와서 textView라는 변수에 담아라
        button =(Button)findViewById(R.id.button);
 
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {  //버튼 클릭하면 실행해라
                for(int i = 0; i<100; i++ ){  
//for(시작,까지,얼마씩){
//동안 계속 (int 타입 i에 0을 담고, i가 100보다 작을 때까지, 순환이 끝나면 i에 1을 더해라){
//몇번동안 { } 를 실행할지 정하는 명령어
 
                    textView.setText(textView.getText().toString() + "\nㅋㅋㅋ" + i);
//textView의, 텍스트를 셋팅해라(textView에.텍스트를 가져와서().스트링 타입으로() + "줄바꾸기 ㅋㅋㅋ" + i);
 
                }
 
 
            }
        });
 
 
 
    }
}
 
 
 

'폐기자료 > 날림 코딩공부' 카테고리의 다른 글

안슈 /4강/for 문, Integer.parseint  (0) 2020.02.21
안슈 /3강 /for문 활용 2  (0) 2020.02.21
홍드로이드/14강 암람다이얼로그  (0) 2020.02.12
안슈/2강/if문 활용2  (0) 2020.02.12
안슈/2강/if문활용 1  (0) 2020.02.12

댓글

Designed by JB FACTORY