[안드로이드 공부]/UI 50

안드로이드 리사이클러뷰 아이템 포지션으로 이동

findViewHolderForAdapterPosition 을 써서 holder 의 itemView를 얻어 올 수 있는 방법이 있다. 즉, 예전 listView의 경우 해당 아이템을 가져와서 크기를 측정(itemView.measure) 한 뒤 리스트의 상단에서 그 아이템 위치 까지 높이를 만들어서 갔었는데, reclyerView에서는 이런 작업을 할 경우, 리스트가 notifychanged 를 하면서 null 이 떨어 질 수 있다. null 을 피하기 위해선 많은 방법을 사용 해야 한다. LinearLayoutManager linearLayoutManager = (LinearLayoutManager)recyclerView.getLayoutManager(); if(linearLayoutManager != ..

안전한 프레그먼트 컨텍스트 사용법 -How to use fragment context ?

프레그먼트 생명 주기 실행 시onAttach —> onCreate() —> onViewCreated() —> onActivicyCreated() —> onResume() 해제시onPause() — > onDestroyView() — > onDestroy() —> onDetach() 즉,안전하게 context 를 사용 하려면 @Override public void onAttach(Context context) { super.onAttach(context); mContext = context; } 요렇게 해서 사용한다.프래그먼트 이곳 저곳에서 getContext(), getActivity() 를 부르다가 Null 이 발생할 수 있기 때문에 이렇게 부르는 것이 안전. 더 안전 하려면 부를 때마다 체크 하는게 ..

안드로이드 리사이클러 뷰 구분선 및 색상 RecyclerView divider color

아주 간단하다.아래 처럼 넣어 주면, 색깔까지 완벽하게! DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mContext,LinearLayoutManager.VERTICAL); dividerItemDecoration.setDrawable(mContext.getResources().getDrawable(R.drawable.recyclerview_divider)); mRecyclerView.addItemDecoration(dividerItemDecoration);아래는 recyclerview_divider.xml

안드로이드 동적 컬러리스트 적용 ColorStateList setTextColor

color/a.xml ColorStateList colorStateList = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { colorStateList = context.getResources().getColorStateList(R.color.a, context.getTheme()); } else { colorStateList = context.getResources().getColorStateList(R.color.a); } textView.setTextColor(colorStateList) 요렇게 하면, 간단하게 컬러 리스트를 동적으로(programmatically) 적용 할 수 있다.

안드로이드 BroadcastReceiver ANR

브로드 캐스트 리시버 에서는 10 초 이내에 모든 작업을 완료 해야함. 그렇지 않으면 시스템이 죽여 버리거나, ANR을 발생 시킨다. 1. onReceive 에서 최대한 간결하게 코드를 처리 한다.1.1 다른 서비스로 리턴 시킨다.1.2 또는 goAsync()를 사용 하여 타임아웃을 연장 한다. 아래는 구글의 설명이다. /** * This can be called by an application in {@link #onReceive} to allow * it to keep the broadcast active after returning from that function. * This does not change the expectation of being relatively * responsive to..