view getId() string 문자 알아보기(EntryName)

안드로이드/android 2013. 3. 26. 11:04

View.OnClickListener clickListener = new View.OnClickListener() {

// TODO clickListener

   public void onClick(final View v) {

       switch (v.getId()) {

           case R.id.photo1:

           case R.id.photo2:

           case R.id.photo3:

            Log.i("ID값",v.getResources().getResourceEntryName(v.getId()));


// 결과 photo1, photo2, photo3

            break;

       }

   }

};

GridView stretchMode

안드로이드/android 2013. 2. 22. 17:39

android:stretchMode android:numColumns="auto_fit" 으로 지정한 경우 열의 나머지 공간 처리 지정


android:stretchMode="columnWidth" : 위젯이 격자 내부를 가득채우게 함

android:stretchMode="spacingWidth" :  남는공간을 여백으로 채움

shape 레이아웃 모서리 둥글게 하기

안드로이드/android 2013. 1. 25. 10:46


// res/drawable/shape.xml

============================================================================

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

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

  <solid android:color="#90000000"/>

  <stroke android:width="4dp" android:color="#50000000"

            android:dashWidth="1dp" android:dashGap="0dp" />

  <padding android:left="7dp" android:top="7dp"

            android:right="7dp" android:bottom="7dp" />

  <corners android:radius="10dp" />  

</shape>



<TextView 

            android:layout_width="wrap_content" android:layout_height="wrap_content"

            android:textSize="16sp" android:textStyle="bold" android:text="모서리 둥글게 하자" android:textColor="#ffffff"

            android:gravity="center" android:background="@drawable/shape"

             android:padding="16px"

        />


배경 이미지 repeat 시키기

안드로이드/android 2013. 1. 25. 10:41

1x1 이미지를 배경으로 반복해서 보이게 하기


====================================================================

// res/drawble/background_image.xml

==================================================================

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

<bitmap

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

  android:src="@drawable/background" android:tileMode="repeat"

/>


// res/layout/background.xml

<LinearLayout android:background="@drawable/background_image.xml" />



=======================================================================

// theme manifest

========================================================================

/res/values/theme.xml


<style name="Theme.BackGround" parent="android:Theme">

        <item name="android:windowBackground">@drawable/background</item>

        <item name="android:windowNoTitle">true</item>

    </style>


/manifest.xml

<activity android:name=".Test" android:label="@string/app_name" android:screenOrientation="landscape" 

        android:theme="@style/Theme.BackGround" />

통화이력 목록으로 뽑아내기

안드로이드/android 2013. 1. 23. 16:20

private Cursor getContacts(){


/**

* Calls.TYPE {1=>수신,2=>송신,3=>부재중전화,5=>수신거부}

*/

final Uri uri =CallLog.Calls.CONTENT_URI;

String[] projection = {

        CallLog.Calls.NUMBER, 

        CallLog.Calls.TYPE,

        CallLog.Calls.CACHED_NAME,

        CallLog.Calls.DATE,

        CallLog.Calls.DURATION

};

String selection=null;

String[] selectionArgs = null;

String sortOrder=CallLog.Calls.DATE + " DESC";


return managedQuery(uri, projection,selection, selectionArgs, sortOrder);

}


private List<Contact> getContactsList() throws Exception 

{

final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

contactsList = new ArrayList<Contact>();

cs = getContacts();

contacts_count = cs.getCount();

if(cs.moveToFirst()){

do {

final String nname = cs.getString(2);

String name="";

if(nname!=null && !nname.equals("")){

Log.i("safasfsda",nname);

name=new String(nname.getBytes(), "utf-8");

}

Log.i("getContactsList",

" NUMBER: "+cs.getString(0)+

" TYPE: "+cs.getString(1)+

" CACHED_NAME: "+name+

" DATE: "+dateFormat.format(cs.getLong(3))+

" DURATION: "+cs.getString(4)

);

} while (cs.moveToNext());

}

return contactsList;

}