전체 글 210

[Android] Fragment 적용 방법

1. fragment를 넣고 싶은 xml에 다음 코드 추가activity_search.xml 2. fragment안에 들어가는 xml 파일 생성=> fragment_search.xml 3. SearchFragment.java 생성 import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; //이걸로 import import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget..

[Android] Activity 전환 시 객체 전달하기! : Parcelable, Serializable

TagNames라는 클래스가 있다.package org.techtown.just; import java.io.Serializable; public class TagNames implements Serializable { private String[] tags = {"행복", "슬픔", "힐링"}; private int[] tagIndex; public String[] getTags() { return tags; } public int[] getTagIndex() { return tagIndex; } public void setTagIndex(int i) { tagIndex[i] = 1; } public TagNames() { tagIndex = new int[tags.length]; for (int i ..

[Android] Checkbox event 체크박스 이벤트 - 체크박스 선택되었을 때

전역변수CheckBox[] cb;@BindView(R.id.checkBox_anything)CheckBox checkBox_anything; onCreate 함수 checkBox_anything.setOnCheckedChangeListener(this); cb = new CheckBox[] {checkBox1, checkBox2, checkBox3}; @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (checkBox_anything.isChecked()) for (int i = 0; i < cb.length; i++) { cb[i].setChecked(false); cb[i].setClickable(..

[Android/Java] Checkbox 선언 시 주의사항!

전역변수로 Checkbox[] c = {checkBox1, checkBox2, checkBox3};그리고 onCreate 함수에서 배열 c를 사용했는데 NullPoint 에러가 났다.    CheckBox[] cb = new CheckBox[] {checkBox1, checkBox2, checkBox3}; 이렇게 작성해주니 오류가 사라졌다.       ==> CheckBox를 배열로 선언할 땐 = new 를 붙여줘야한다!   @BindView(R.id.checkBox1)CheckBox checkBox1;@BindView(R.id.checkBox2)CheckBox checkBox2;@BindView(R.id.checkBox3)CheckBox checkBox3;※ checkBox1,2,3은 위와같이 정의되어..

[Android] FLAG: CLEAR_TOP

액티비티 A, B가 있다.A->B->A->B->A->B... 계속 호출하게 되면 스택엔 ABABAB가 계속 쌓여 뒤로가기를 누르면BABABA 순으로 두 개의 액티비티가 반복적으로 보일 것이다.그냥 B에서 뒤로가기누르면 A로, A에서 뒤로가기 누르면 종료시킬 순 없는 것인가? 있다! FLAG를 이용하면 된다.많은 FLAG가 있지만 오늘은 CLEAR_TOP만을 이용해볼 것이다.  MainActivity2.java 파일이다. @Override public void onClick(View view) { Intent intent; switch(view.getId()) { case R.id.btn_main: intent = new Intent(this, MainActivity.class); intent.setFla..

[Android] SharedPreferences 앱이 종료되어도 작성하던 글은 그대로 유지하는 방법!?

글을 쓰다가 앱이 종료되었을 때, 글이 사라지지 않도록 하는 방법!       String sfName = "myFile";@BindView(R.id.editText1)EditText editText1;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ButterKnife.bind(this);// 지난번 저장해놨던 사용자 입력값을 꺼내서 보여주기 SharedPreferences sf = getSharedPreferences(sfName, 0);String str = sf.getString("name", ""); //..

[Android] ButterKnife 사용법, findViewById 너무 귀찮을 때!!

1. Butterknife란?findViewById를 일일히 써주는 작업이 귀찮게 느껴질 때가 많다.이 불편함을 한방에 해소시켜주는 라이브러리!!2. 사용법 - build.gradle에 다음 두 줄 작성 후 syncimplementation 'com.jakewharton:butterknife:8.8.1'annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' - android studio에서 shift를 두번 누르면 나오는 검색창에 plugin 검색, Actions - Plugins 클릭- 하단 browse repositories 버튼 클릭- Android butterknife zelezny 검색 후 install, restart android ..

출처: https://mingos-habitat.tistory.com/34 [밍고의서식지:티스토리]