가장 많이 사용되는 id와 class 셀렉터를 먼저 알아보겠습니다.

1. class 셀렉터

<div class="test">class 테스트입니다.</div>
<div id="test">id 테스트입니다.</div>

ex) $( ".text" ).text( "The DOM is now loaded" );

=> 실행 결과

The DOM is now loaded
id 테스트입니다.

* class selector는 앞에 을 붙여서 선택할 수 있습니다.
------------------------------------------------------------------------

2. id 셀렉터

<div class="test">class 테스트입니다.</div>
<div id="test">id 테스트입니다.</div>

ex) $( "#text" ).text( "The DOM is now loaded" );

=> 실행 결과

class 테스트입니다.
The DOM is now loaded

* id selector는 앞에 을 붙여서 선택할 수 있습니다.
------------------------------------------------------------------------

위 두개의 셀렉터를 가장 많이 사용하고 두 개만 이용해도 거의 모든 기능을 다루는데 문제 없이 활용할 수 있습니다.

추가로 jquery 에서 제공하는 다양한 셀럭터들을 맛보기로 몇개만 소개하겠습니다.

1. all selector  ("*")

ex) $("*").css("border", 3px solid red");

-----------------------------------------------------------------------------------------------

2. 속성 prefix 셀렉터 [name|=”value”]

<a href="example.html" hreflang="en">Some text</a>
<a href="example.html" hreflang="en-UK">Some other text</a>
<a href="example.html" hreflang="english">will not be outlined</a>


ex) $( "a[hreflang|='en']" ).css( "border", "3px dotted green" );


=> 실행 결과

Some text Some other text will not be outlined

-----------------------------------------------------------------------------------------------

3. 문자를 포함하는 셀렉터  [name*=”value”]

<input name="man-news">
<input name="milkman">
<input name="letterman2">
<input name="newmilk">

ex) $( "input[name*='man']" ).val( "has man in it!" );

=> 실행 결과

   

-----------------------------------------------------------------------------------------------

4. 단어를 포함하는 셀렉터  [name~=”value”]

<input name="man-news">
<input name="milkman">
<input name="letterman2">
<input name="newmilk">

ex) $( "input[name*='man']" ).val( "mr. man is in it!" );

=> 실행 결과

   

-----------------------------------------------------------------------------------------------


jquery 셀렉터에 대해 간략하게 소개하였습니다~

다음 강의에서 만나요~


+ More jQuery

 - [jQeury] jquery this, 코드 줄이기, jquery index, 인덱스

 - [jQuery] - jQeury] val(), text() 값 셋팅, 값 가져오기 setValue, setText

 - [jQuery] - [jQeury] jquery 클래스 추가(addClass), class 추가 삭제(removeClass) 및 확인(hasClass)

 - [jQuery] - [jQeury] jquery tigger, jquery 함수 실행, 이벤트 실행

 - [jQuery] - [jQeury] jQuery css, jQuery 스타일 적용


요즘 안드로이드 샘플 앱들을 보면 Library가 jar파일이 아닌 프로젝트 형태로 제공되는 경우가 많다. 안드로이드 프로젝트를 Library로 추가하는 방법에 알아보자~


1. Properties > Android > Library 추가





추가할 수 있는 Library들이 나타나고 추가할 Library를 선택 후 저장합니다.


2. project.properties 경로 추가





직접 project.properies 파일에 경로를 입력하여 추가할 수 있습니다.


샘플 프로젝트를 받았는데 엑박 표시가 뜨면서 실행이 안된다면 당황하지 말고 먼저 프로젝트 Library 추가할 게 있는지 확인해보시기 바랍니다~






채팅 앱을 개발하다 보면 채팅 activity가 백그라운드에 내려가 있을 때 현재 채팅중인 상대방이 아닌 다른 사람에게 메세지가 와서 nofitication을 누르게 되면 같은 activity가 두 개 뜨는 현상이 발생한다.

이런 현상을 막기 위해 Acitivty LaunchMode를 변경하여 단일 activity만 활성화 되도록 설정한다.

<activity android:name="ChattingAcitivity"

android:screenOrientation="portrait" 

android:windowSoftInputMode="adjustResize"

android:launchMode="singleTask" />


activity 설정을 singleTask로 설정하여 단일 activity 설정 적용 완료!


단 이렇게 설정했을 때 onResume에서 intent 데이터를 받을 시에 

getIntent 값이 변경되지 않는 문제점이 발생한다..

Intent 값 변경은 다음 포스팅에 계속!



연재 안드로이드 카카오 UI 채팅 

드로이드에서 리스트 알림창 List AlertDialog를 띄우는 방법에 대해 포스팅합니다.

Summary


 Public Constructors

 

 AlertDialog.Builder(Context context)

Constructor using a context for this builder and the AlertDialog it creates.

 

 AlertDialog.Builder(Context context, int theme)

Constructor using a context and theme for this builder and the AlertDialog it creates.

스타일을 지정하여 생성할 수 있습니다.


- 실행화면



- 코드 



final String[] items = { "One", "Two", "Three" };

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle("Title");

builder.setItems(items, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

if (which == 0) {

} else if (which == 1) {

}

}

});

builder.create();

builder.show();



참고 사이트 : developer.android.com


궁금한 사항이나 수정은 댓글로 남겨주세요~


드로이드에서 알림창 AlertDialog를 띄우는 방법에 대해 포스팅합니다.

Summary


 Public Constructors

 

 AlertDialog.Builder(Context context)

Constructor using a context for this builder and the AlertDialog it creates.

 

 AlertDialog.Builder(Context context, int theme)

Constructor using a context and theme for this builder and the AlertDialog it creates.

스타일을 지정하여 생성할 수 있습니다.

다이얼로그 만들기

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Dialog")
        .setMessage("This is Dialog")
        .setCancelable(true)
        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
            // 확인 버튼 클릭시 설정
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.dismiss();
            }
        })
        .setNegativeButton("Cancle", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.cancel();
            }
        });
builder.create();
builder.show();



참고 사이트 : developer.android.com


궁금한 사항이나 수정은 댓글로 남겨주세요~

드로이드에서 화면 사이즈를 구하는 방법에 대해 포스팅합니다.


DisplayMetrics Class를 이용하여 화면 사이즈를 구합니다.

Class Overview


A structure describing general information about a display, such as its size, density, and font scaling.

To access the DisplayMetrics members, initialize an object like this:

 DisplayMetrics metrics = new DisplayMetrics();
 getWindowManager
().getDefaultDisplay().getMetrics(metrics);

- 가로 사이즈 구하기

deviceWidth = displaymetrics.widthPixels;

- 세로 사이즈 구하기 

deviceHeight = displaymetrics.heightPixels;


참고 사이트 : developer.android.com


궁금한 사항이나 수정은 댓글로 남겨주세요~


안드로이드에 google analystics를 적용하는 방법에 대해 포스팅합니다.

google analystics를 적용하는데 한참 헤매서 다음에 하시는 분들은 조금 편하게 하실수 있기를 바랍니다. ㅎㅎ


1. google Analytics 가입하기 

google Analytics를 사용하시려면 가입을 먼저 하셔야겠죠? ㅎㅎ

가입 후 새 계정을 만들고 계정에 발급된 UA-XXXXXXXX-X 로 시작하는 번호를 확인합니다.


2. 라이브러리 다운로드

libGoogleAnalyticsServices.jar

라이브러리를 다운 받고 프로젝트에 추가시켜줍니다.


3. Initialization

Before any data can be measured, you must initialize at least one tracker via GoogleAnalytics singleton by providing a Context and a Google Analytics property ID:

// Initialize a tracker using a Google Analytics property ID.
Tracker tracker = GoogleAnalytics.getInstance(this).getTracker("UA-XXXX-Y")

먼저 계정에 발급된 속성 번호로 tracker를 초기화합니다.

이제 모든 준비가 끝났습니다~ 참 쉽죠?!

4. 데이터 전송

-. HashMap 형태로 데이터를 보낼 수 있습니다.

Data is sent to Google Analytics by setting maps of parameter-value pairs on the tracker and sending them via the set and sendmethods:

/*
 * Send a screen view to Google Analytics by setting a map of parameter
 * values on the tracker and calling send.
 */

Tracker tracker = GoogleAnalytics.getInstance(this).getTracker("UA-XXXX-Y");

HashMap<String, String> hitParameters = new HashMap<String, String>();
hitParameters
.put(Fields.HIT_TYPE, "appview");
hitParameters
.put(Fields.SCREEN_NAME, "Home Screen");

tracker
.send(hitParameters);


-. Screen 이름을 설정하여 보낼 수 있습니다.

-. 가장 많이 사용하고 단순해서 추천하는 방식이라는 거 같습니다. ㅎㅎ


The MapBuilder class simplifies the process of building hits and is recommended for most use cases. Here we can send the same screen view with fewer lines of code:

// Sending the same screen view hit using MapBuilder.createAppView()
tracker
.(MapBuilder
 
.createAppView()
 
.set(Fields.SCREEN_NAME, "Home Screen")
 
.build()
);


-. Applying Values to Multiple Hits

-. 화면 이름을 설정하고 안에서 화면에서 이벤트에 대한 tracker를 설정하여 전송할 수 있습니다.

Any values set on the tracker directly will be persisted and applied to muliple hits, as in this example:

// Set screen name on the tracker to be sent with all hits.
tracker
.set(Fields.SCREEN_NAME, "Home Screen");

// Send a screen view for "Home Screen"
tracker
.send(MapBuilder
   
.createAppView()
   
.build()
);

// This event will also be sent with &cd=Home%20Screen.
tracker
.send(MapBuilder
   
.createEvent("UX", "touch", "menuButton", null)
   
.build()
);

// Clear the screen name field when we're done.
tracker
.set(Fields.SCREEN_NAME, null);

An event consists of four fields that you can use to describe a user's interaction with your app content:

Field NameTracker FieldTypeRequiredDescription
CategoryFields.EVENT_CATEGORYStringYesThe event category
ActionFields.EVENT_ACTIONStringYesThe event action
LabelFields.EVENT_LABELStringNoThe event label
ValueFields.EVENT_VALUELongNoThe event value

이벤트에 대한 field는 category와 action은 꼭 넣어주시구요!


아래 퍼미션 추가는 이전 버전인거 같으나 혹시 몰라 추가해두었습니다.

안되면 추가해주세요(필수인지는 확인 안해봤습니다 ㅎㅎ;)


Update your AndroidManifest.xml file by adding the following permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


코드 적용이 완료 되면 가입하신 google Analysics 사이트에서 실시간 탭에서 바로바로 확인이 가능합니다.


참고 사이트 : developer.android.com


궁금한 사항이나 수정은 댓글로 남겨주세요~



 

+ Recent posts