ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 안드로이드 코드 스니펫 | 예제
    Android 2020. 3. 16. 00:24

    인터넷 허용 권한 추가시

    <uses-permission android:name="android.permission.INTERNET" />

    액티비티 추가시

    <activity abdroid:name=".addedActivity">

     

    이벤트 등록 방법 5가지 //1.익명class 2.익명 switch 3.리스너클라스_구현 4.MainActivity를 리스너class_구현5.xml_onlick

    이벤트 등록 ,다른 액티비티에 인텐트 전달  

    //nameofActivity 
    	Button b = (Button)findViewById(R.id.button1);
        b.setOnClickListener(new View.OnClickListener() {
        @Override
        	public void onClick(View view) {
            Handmadeclass iamclass =new Handmadeclass();   //보낼 클래스 선언
            String[] array = {"홍길순","김춘추","김유신"}; //보낼 배열
            
            Intent intent = new Intent(nameofActivity.this,SubActivity.class); // (현재class,보낼 class)
            
            //(보내는 메시지 이름,내용)
            intent.putExtra("nameOfMessage","data");//String
            intent.putExtra("class",iamclass);      //class //Serializable구현된 class
            intent.putExtra("array",array);			//배열[]
            intent.putExtra("thisisint",5);			//int
            
            startActivity(intent); // 
            }
        });
    //SubActivity
            TextView tx1 = (TextView)findViewById(R.id.textView1); /*TextView선언*/
            TextView tx2 = (TextView)findViewById(R.id.textView2);
            TextView tx3 = (TextView)findViewById(R.id.textView3);
            TextView tx4 = (TextView)findViewById(R.id.textView4);
            TextView tx5 = (TextView)findViewById(R.id.textView5);
    
            Intent intent = getIntent(); /*데이터 수신*/
    
            String name = intent.getExtras().getString("name"); /*String형*/
            int age = intent.getExtras().getInt("age"); /*int형*/
            String array[] = intent.getExtras().getStringArray("array"); /*배열*/
            Option option = (Option)intent.getSerializableExtra("class"); /*클래스*/
            
            tx1.setText(name);      
            tx2.setText(String.valueOf(age));
            tx4.setText(option.getPhone());
            tx5.setText(option.getAddr());
            
            String add_array="";
            for(int i=0;i<array.length;i++){
                add_array+=array[i]+",";
            }
            tx3.setText(add_array);

    이벤트 등록 //switch 문 이용

        Button button1;
        Button button2;
        Button button3;
        SearchView searchView;
        Toast  toast;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            button1     =(Button)      findViewById(R.id.button1);
            button2     =(Button)      findViewById(R.id.button2);
            button3     =(Button)      findViewById(R.id.button3);
            searchView  =(SearchView)  findViewById(R.id.searchView);
            toast       =Toast.makeText(this.getApplicationContext(),"",Toast.LENGTH_LONG);
            button1.setOnClickListener(clickListener);
            button2.setOnClickListener(clickListener);
            button3.setOnClickListener(clickListener);
    
        }
        View.OnClickListener clickListener =new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                case R.id.button3 :
    //                    Intent intent = new Intent(MainActivity.this, webview.class);
    //                    intent.putExtra(dataName, String.valueOf(editText.getText()));
    //                    startActivity(intent);
                    toast.setText("this is for testing of hct");
                    toast.show();
                    break;
            }
        }
        };

    Toast 사용

    Toast myToast =Toast.makeText(this.getApplicationContext(),"data context",Toast.LENGTH_SHORT);

    myToast.show();

    myToast.cancel();

    리스트뷰 구현

    https://lktprogrammer.tistory.com/163

    Jsoup을 이용한 web parsing

    https://m.blog.naver.com/hwa2ting3612/221471745071

    네이버 상영중인 영화 불러오기 with image( Jsoup+Glide +listView)

    https://m.blog.naver.com/cosmosjs/221294678259

     

     

     

     

     

     

     

     

     

     

    댓글 0

Designed by Tistory.