레이블이 Android인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Android인 게시물을 표시합니다. 모든 게시물 표시

12/28/2014

Fragment onCreateView가 호출되지 않는 문제(not called)

Fragment 안의 fragment의 onCreateView가 호출되지 않는 문제로

Outer Fragment는 잘 호출된다.

ViewPager의 Fragment manager를 쓸 때 parent와 child가 구분되어 있기에 안쪽에서는 child fragment manager로 ViewPager를 만들어야 정상적으로 호출이 된다.

// In parent
pageAdapter = new ViewPagerAdapter(getFragmentManager()); 
// In child
pageAdapter = new ViewPagerAdapter(getChildFragmentManager());


Ref: http://stackoverflow.com/questions/6672066/fragment-inside-fragment

6/13/2014

Android - Broadcast 등록 후에, Broadcast send가 안되는 문제!

I was having the same problem as you, but I figured out:
Remove the intent filter from the manifest and change
Intent intent=new Intent(getApplicationContext(),WebResults.class);
for
Intent intent=new Intent();
Hope it helps!
Reference :

http://stackoverflow.com/questions/3907713/how-to-send-and-receive-broadcast-message


Inner Class로 만든 Broadcast Receiver를 동적으로 register 해줘서 그런가?


5/09/2014

Android - 안드로이드 스튜디오(Android Studio)에서 ViewPagerIndicator library gradle로 사용하기

/Android-ViewPagerIndicator


View PagerIndicator github 페이지에서 Including In Your Project를 보면 Maven 사용법만 나와 있다.  

이럴땐 mvnrepository.com 이나 search.maven.org 에서 dependencies를 찾아보면 되더라... 그런데 엄습해오는 불안감... 된다면 적어놓았겠지 하는...?

dependencies {
       // ... other ommitted
       compile 'com.viewpagerindicator:library:2.4.1'
       // ...
    }


역시나 위의 코드만으로는 작동을 하지 않는다.

열심히 삽질한 결과

project root에 위치한 build.gradle에

repositories {
    maven { url "http://dl.bintray.com/populov/maven" }
    mavenCentral()
}

하위 forder의 build.gradle에

dependencies {
    // ...
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    // ...
}
를 설정한다.

이렇게 해야하는 이유가 aar이라는 gradle에서 지원하는 방식을 만든 애들이 지원안해서 다른 곳에서 하고 있다고 한다. (아마도?)


Reference : http://stackoverflow.com/questions/21130003/using-viewpagerindicator-library-with-android-studio-and-gradle

5/07/2014

Android - Dynamically query using variable from string.xml file

ViewPager 쓰면서 각 Fragment number 별로, string만 바꿔주면 되었다.

그래서 switch나 if문으로 매번

getString(R.string.fragment_0)
getString(R.string.fragment_1)
getString(R.string.fragment_2)
...

를 해야하나 싶어서,

뒤의 숫자만 바꿔서 가져오는 방법을 찾으려했다.



int resId = getResources().getIdentifier("key_name", "string", getPackageName());

key_name과 찾고자 하는 R 이하의 항목, 그리고 Package name으로 Resource Id를 가져올 수 있는 함수가 존재했다!

Reference : http://stackoverflow.com/questions/6265417/dynamically-querying-a-string-is-strings-xml-file

Android - ViewPager 사용하기

Reference : http://developer.android.com/reference/android/support/v13/app/FragmentStatePagerAdapter.html

5/05/2014

Android - EditText Cursor 깜빡이도록 보이게 하기

android:textCursorDrawable="@null"

Reference : http://stackoverflow.com/questions/18339552/edittext-cursor-becomes-invisible-in-jellybean

Android - EditText에서 Enter Action 처리하기

검색창을 만들려고 했더니 EditText의 Attribute에

android:imeOptions="actionSearch" 라는 것이 가능했다.

그러면 흔히 보는 Enter의 화살표 대신, 돋보기로 나온다.

그리고 해당 Action이 setOnEditorActionListener를 통해 처리될 수 있다.


Reference : http://ccdev.tistory.com/31

Android - 키보드 보이기, 숨기기

일단 키보드가 제대로 안나타난다면 이전 포스트에서 언급한 것을 떠올려보자.

 키보드가 자체가 사라지는 문제는 manifest의

android:windowSoftInputMode="adjustPan" 

가 핵심이다.


/**
 * Hides the soft keyboard
 */
public void hideSoftKeyboard() {
    if(getCurrentFocus()!=null) {
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }
}

/**
 * Shows the soft keyboard
 */
public void showSoftKeyboard(View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    view.requestFocus();
    inputMethodManager.showSoftInput(view, 0);
}

showSoftKeyboard 의 파라미터 없이 직접 원하는 view를 넣어도 된다.

Reference : http://stackoverflow.com/questions/18977187/how-to-hide-soft-keyboard-when-activity-starts

Android - ListView의 onScrollStateChanged Event에서 일부 버벅이는 문제

이상하게 랙 걸린 것 처럼 안움직이다가, 

스크롤 한번 해주면 여태 쌓인 이벤트가 한번에 발생하는 문제다.

이는 onScrollStateChanged에서 

adapter.notifyDataSetChanged 를 해주면 되는 것 같다.


Android - EditText in ListView lost focus. 리스트뷰 안의 입력창의 포커스가 사라지는 문제

리스트뷰 내부의 EditText의 문제가 두 가지 있다.


  1. 키보드 자체가 사라지는 문제
  2. EditText의 focus가 사라지는 문제


처음으로, 키보드가 자체가 사라지는 문제는 manifest의

android:windowSoftInputMode="adjustPan" 

가 핵심이다.


I have seen that some solutions are using:
android:descendantFocusability="beforeDescendants"
in the layout of the definition of the list.
For me this wasn't necessary. The problem was fixed using android:windowSoftInputMode="adjustPan":
<activity
        android:name="mainActivity"
        android:windowSoftInputMode="adjustPan"
        android:label="@string/app_name" >
    </activity>
in the Manifest.xml.
But you have to make sure that this line of code goes in the activity where you are defining the TabHost or TabActivity!!!.


Reference : http://stackoverflow.com/questions/17003715/edittext-inside-listview-lost-focus


두 번째 문제로,  EditText의 Focus가 사라지는 문제는

ListView가 Focus를 가져간다는 것 같다.

그래서 Focus를 뺏기지 않도록, onItemSelected를 Override해서

직접 Focus 관리를 한다.

내용은 링크 참조.

Reference : http://stackoverflow.com/questions/2679948/focusable-edittext-inside-listview

5/02/2014

Android - this, getContext(), getApplicationContext(), getBaseContext() 차이

  • this == getContext()
  • View.getContext(): Returns the context the view is currently running in. Usually the currently active Activity.
  • Activity.getApplicationContext(): Returns the context for the entire application (the process all the Activities are running inside of). Use this instead of the current Activity context if you need a context tied to the lifecycle of the entire application, not just the current Activity.
  • ContextWrapper.getBaseContext(): If you need access to a Context from within another context, you use a ContextWrapper. The Context referred to from inside that ContextWrapper is accessed via getBaseContext().


5/01/2014

Android - Child Selector의 효과를 Parent에게도 적용하기

버튼 클릭 시, 배경색 변화를 주기 위해 selector를 사용한다.

여기서 더 나아가, 확실한 피드백을 주기 위해 Parent인 LinearLayout의 배경색도

바꾸게 하려고 하였다.

해결 방법은 Parent에다 addStatesFromChildren="true"를 해주면 그냥 되지는 않는다.

background를 고정해놓았다면 아무 변화가 없을 것이다. 

state만 공유하는 것이지, state에 따른 action까지 공유하지 않는다.

따라서, Parent에도 selector를 달아주면 해결!



Reference : http://stackoverflow.com/questions/10605647/android-make-parent-selector-trigger-when-selecting-child

4/28/2014

[Android] ListView의 첫번째와 마지막 Item(Content)의 Padding을 주고 싶으면?


ListView를 쓰면서 첫번째와 마지막 Item의 Padding이 있어야 배경이 자연스럽게 보일 것 같았다.

생각한 방법은

  1. ListView의 Margin을 적용
  2. ListView의 Padding을 적용
  3. ListView의 첫번째와 마지막 Item Layout에 Margin 적용
  4. 높이만 적용된 비어있는 View를 삽입

결과는 
  1. 안됨
  2. 안됨
  3. 안됨
  4. 번거로움. 뭔가 몸이 이건 아니다고 말함. StackOverflow에 물어보아야 할 느낌이 옴.


역시나 찾으니 방법은 있다.

ClipToPadding이라는 Attribute를 false하면 padding을 clip(유지? 고정?)하고 있는 것을 해제하나 보다.




Reference:

http://stackoverflow.com/questions/6288167/add-margin-above-top-listview-item-and-below-last-in-android#

http://www.kmshack.kr/400

[Android] TextView 일부분의 색상을 바꾸기

Easiest way I know is to just use html.
String first = "This word is ";
String next = "<font color='#EE0000'>red</font>";
t.setText(Html.fromHtml(first + next));
But this will require you to rebuild the TextView when (if?) you want to change the color, which could cause a hassle.

Html 코드가 먹는다니 신기하다. 심심해서 찾아봤는데 실제로 될줄이야.



Reference : http://stackoverflow.com/questions/7221930/change-text-color-of-one-word-in-a-textview

2/24/2014

android 개발 이슈 14/02/24

1. Java Android Thread에서 리턴값 받기
http://plaboratory.org/archives/108


2. static과 final의 차이
http://blog.naver.com/PostView.nhn?blogId=alsdl118&logNo=140123480294


3. 폰에서 request 쏘면 모바일 페이지로 가져서 파싱할 때 주의해야 한다....

4. jsoup에서 span의 value를 가저올땐

element.attr("value");  // x

element.text(); //o




<span>what</span> 에서 what 을 뭐라고 불리는 거지? 위의 문제를 해결하기 위해선 이 의문부터 풀고 가야될거 같다