2013년 11월 23일 토요일

[안드로이드 앱 개발] 어댑터와 어탭터 뷰에 대해 알아보자.

어탭터 뷰에는 리스트 뷰, 그리드 뷰, 스피너, 갤러리 등이 있는 데

이 모두는 집합항목을 표시하는 위젯이다.


어탭터 뷰는 태생부터 ViewGroup으로부터 파생되므로 여러 뷰를

가지는 것이 가능하게 설계되어 있다.


이 위젯들이 어탭터 뷰라고 불리는 결정적인 이유는 어댑터(Adapter)로부터

데이타를 공급받기 때문이다.


Adapter는 원본으로부터 얻은 데이타를 관리하며 뷰를 생생하는 역할을 한다.

AdapterView는 Adapter가 전달한 데이터를 화면에 표시하는 역할만을 한다.


2013년 11월 14일 목요일

[안드로이드 앱 개발] Your content must have a ListView whose id attribute is 'android.R.id.list'

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.philtelbook/com.example.philtelbook.DataListActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'


ListViewActivity를 사용하려면 반드시 ListView의 아이디를 list로 지정하라는 이야기입니다.

xml에 다음과 같이 지정해주세요. 반드시......

android:id="@android:id/list"

2013년 11월 11일 월요일

[안드로이드 앱 개발] 안드로이드 형변환

// 숫자에서 문자로 바꾸기
String si = Integer.toString(numval)
String sf = Float.toString(numval)
String sl = Long.toString(numval)
String sd = Double.toString(numval)

// 문자에서 숫자로 바꾸기
int i = Integer.parseInt(strval);
float f = Float.parseFloat(strval);
long l = Long.parseLong(strval);
double d = Double.parseDouble(strval);

2013년 10월 29일 화요일

[안드로이드 앱 개발] StrictMode$AndroidBlockGuardPolicy.onNetwork... 에러가 발생할때

Error Message:  
                at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork
                (StrictMode.java:1077)

위의 에러를 해결하기 위해서는 아래의 두 가지 조치를 해줘야한다.

1. 안드로이드 3.X버전이상에서 인터넷 통신(소켓, http)을 통해서 연결을 할때는 메인스레드에서는 안되고 스레드를 꼭 하나더 만들어 연결을 해야되고 UI를 업데이트하기 위해서는 핸들러를 꼭 사용해야 된다.

2.   StrictMode.enableDefaults()를 삽입해야한다. 
      단, 안드로이드 최소버전을 9이상으로 맞춰야 위의 API사용이 가능하다.
   public void onCreate(Bundle savedInstanceState) {        
     StrictMode.enableDefaults();   
     super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

[안드로이드 앱 개발] ContentResolver에 대해 알아보자

ContentResolver는 추상클래스입니다.

<원문> This class provides applications access to the content model.

이 클래스는 앱들이 데이타에 접근할 수 있는 방법을 제공합니다.

<원문>Content providers manage access to a structured set of data. They encapsulate the data, and provide mechanisms for defining data security. Content providers are the standard interface that connects data in one process with code running in another process.
When you want to access data in a content provider, you use the ContentResolver object in your application's Context to communicate with the provider as a client. The ContentResolver object communicates with the provider object, an instance of a class that implements ContentProvider. The provider object receives data requests from clients, performs the requested action, and returns the results.
You don't need to develop your own provider if you don't intend to share your data with other applications. However, you do need your own provider to provide custom search suggestions in your own application. You also need your own provider if you want to copy and paste complex data or files from your application to other applications.
Android itself includes content providers that manage data such as audio, video, images, and personal contact information. You can see some of them listed in the reference documentation for the android.provider package. With some restrictions, these providers are accessible to any Android application.
The following topics describe content providers in more detail:
Content Provider Basics
How to access data in a content provider when the data is organized in tables.
Creating a Content Provider
How to create your own content provider.
Calendar Provider
How to access the Calendar Provider that is part of the Android platform.
Contacts Provider
How to access the Contacts Provider that is part of the Android platform.