Programming/Android2014. 4. 17. 15:33

phoneNum = PhoneNumberUtils.formatNumber(phoneNum);

Posted by WI_K
Programming/Android2014. 4. 17. 15:25

public void getAllPhoneContacts(Context context) {


Log.d("START", "Getting all Contacts");


contactList = new ArrayList<Contact>();


Contact contact = null;


Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;


Cursor cursor = context.getContentResolver().query(

uri,

new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER,

ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,

ContactsContract.CommonDataKinds.Phone._ID }, null,

null,

ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");


cursor.moveToFirst();


while (cursor.isAfterLast() == false) {

String contactNumber = cursor

.getString(cursor

.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

String contactName = cursor

.getString(cursor

.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));

String phoneContactID = cursor

.getString(cursor

.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID));


contact = new Contact();

contact.setId(phoneContactID);

contact.setName(contactName);

contact.addPhone_num(contactNumber);


if (contact != null) {

contactList.add(contact);

}

contact = null;


cursor.moveToNext();

}

cursor.close();

cursor = null;

Log.d("END", "Got all Contacts");


}

'Programming > Android' 카테고리의 다른 글

(ListView) click했을 때 해당 custom Item 가져 오는 법  (0) 2014.04.29
전화번호 형식 지정  (0) 2014.04.17
(ListView) 터치시 색 변경  (0) 2014.04.10
Resource 가져오기  (0) 2014.04.10
Hash 사용  (0) 2014.04.09
Posted by WI_K
Programming/Java2014. 4. 16. 15:06

new StringBuilder(hi).reverse().toString()

'Programming > Java' 카테고리의 다른 글

8자리 난수구하기  (0) 2014.06.09
현재 시간 구하기  (0) 2014.06.06
난수(Random Number) 출력  (0) 2014.05.15
(Java) Byte Array to Binary and Binary to Byte Array  (0) 2014.04.14
Posted by WI_K
Programming/Java2014. 4. 14. 20:31

public static String byteArraytoBinary( byte[] bytes ){

   StringBuilder sb = new StringBuilder(bytes.length * Byte.SIZE);

   for( int i = 0; i < Byte.SIZE * bytes.length; i++ )

       sb.append((bytes[i / Byte.SIZE] << i % Byte.SIZE & 0x80) == 0 ? '0' : '1');

   

   return sb.toString();

}

public static byte[] binaryToByteArray( String s ){

   int sLen = s.length();

   byte[] toReturn = new byte[(sLen + Byte.SIZE - 1) / Byte.SIZE];

   char c;

   for( int i = 0; i < sLen; i++ )

       if( (c = s.charAt(i)) == '1' )

           toReturn[i / Byte.SIZE] = (byte) (toReturn[i / Byte.SIZE] | (0x80 >>> (i % Byte.SIZE)));

       else if ( c != '0' )

           throw new IllegalArgumentException();

   return toReturn;

}

'Programming > Java' 카테고리의 다른 글

8자리 난수구하기  (0) 2014.06.09
현재 시간 구하기  (0) 2014.06.06
난수(Random Number) 출력  (0) 2014.05.15
(Java) String 반대로 순서 변경  (0) 2014.04.16
Posted by WI_K
Programming/Android2014. 4. 10. 20:20


1. 안드로이드 res 폴더에 drawable 폴더가 없을 시 생성

2. Drawable 폴더에 ListView_Selector.xml 파일 생성 (이름 자유)

3. Selector 속성지정


<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item

        android:state_focused="true"

        android:drawable="@color/yellow"

    />

<item

        android:state_pressed="true"

        android:drawable="@color/yellow"

    />

    <item

        android:state_activated="true"

        android:drawable="@color/yellow"

    />

    <item

        android:state_selected="true"

        android:drawable="@color/yellow"

    />

<item android:drawable="@color/white"/>

 

</selector>


3. ListView에 속성 지정

android:listSelector="@drawable/listview_selector"

listview_selector는 추가했던 파일 이름

'Programming > Android' 카테고리의 다른 글

(ListView) click했을 때 해당 custom Item 가져 오는 법  (0) 2014.04.29
전화번호 형식 지정  (0) 2014.04.17
연락처 빠르게 불러오기  (0) 2014.04.17
Resource 가져오기  (0) 2014.04.10
Hash 사용  (0) 2014.04.09
Posted by WI_K
Programming/Android2014. 4. 10. 10:37

-Color

setTextColor()일 경우와 setBackgroundResource()일 경우가 다르다. 

colors.xml에서 색 정보를 가져올 때의 경우를 알아보자.


1. setColor()일 경우

적용 대상: setTextColor()

사용 방법: setTextColor(getResources().getColor(R.color.gray));


2. setBackgroundResource()일 경우

적용 대상: setBackgroundResource()

사용 방법: setBackgroundResource(R.color.gray);


따라서 Resource가 붙으면 굳이 getResources().getColor()를 붙일 필요가 없다.


※응용

-String

getResources().getString(R.string.volunteer_full);

'Programming > Android' 카테고리의 다른 글

(ListView) click했을 때 해당 custom Item 가져 오는 법  (0) 2014.04.29
전화번호 형식 지정  (0) 2014.04.17
연락처 빠르게 불러오기  (0) 2014.04.17
(ListView) 터치시 색 변경  (0) 2014.04.10
Hash 사용  (0) 2014.04.09
Posted by WI_K
Programming/Android2014. 4. 9. 19:18

HashMap<"key가 되는 자료형", "저장할 자료형"> examMap = new HashMap<"key가 되는 자료형", "저장할 자료형">();


-저장할 때

examMap .put("key 값", "data");

 

-가져올 때

examMap .get("key 값");


-HashMap은 동기화 되어있지 않으므로 여러 쓰레드에서 접근할 때는 동기화를 시켜줘야 한다.


-참조

http://developer.android.com/reference/java/util/HashMap.html

'Programming > Android' 카테고리의 다른 글

(ListView) click했을 때 해당 custom Item 가져 오는 법  (0) 2014.04.29
전화번호 형식 지정  (0) 2014.04.17
연락처 빠르게 불러오기  (0) 2014.04.17
(ListView) 터치시 색 변경  (0) 2014.04.10
Resource 가져오기  (0) 2014.04.10
Posted by WI_K