728x90

새로운 Activity를 띄우지 않고 Windows의 팝업 창처럼 그냥 창을 띄워 상태 알람/진행을 표시하는 녀석이다.
아래 Sample은 각각 종류별로 정리했다. 종류는 아래와 같다.


  • Basic Alert - 아주 기본적인 Alert Dialog
  • Button add - Dialog 창에 Button이 추가
  • List type - 여러가지 항목을 선택
  • CheckBox type - CheckBox가 포함
  • RadioButton type - RadioButton이 포함(미리 체크 항목을 선택 할 수 있음)
  • ProgressDialog type - 동그란 에니메이션이 동작함
  • ProgressBar type - 막대 형태로 진행 상태를 표시함
  • Custom Dialog - 임의 디자인을 적용

 

1. Basic Alert

 

  

AlertDialog.Builder ab = null;
ab = new AlertDialog.Builder( AlertDialogTest.this );
ab.setMessage( Html.fromHtml("<b><font color=#ff00ff> HTML View</font></b><br>Android.com"));
ab.setPositiveButton(android.R.string.ok, null);
ab.setTitle( "Basic Alert Dialog" );
ab.show();

 

2. Button add

 

 

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(getApplicationContext(), "ID value is " + Integer.toString(id), Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(getApplicationContext(), "ID value is " + Integer.toString(id), Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});

AlertDialog alert = builder.create();
alert.show();

 

3. List type

 

 

final CharSequence[] items = {"Red", "Green", "Blue"};

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
alert.show();

 

4. RadioButtons type

 

 

final CharSequence[] items = {"Red", "Green", "Blue"};

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
alert.show();

 

5. Checkboxes type

 

 

final CharSequence[] items = {"Red", "Green", "Blue"};
final boolean[] itemsChecked = {false, true, false };

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setMultiChoiceItems( items, itemsChecked, new DialogInterface.OnMultiChoiceClickListener() {

@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
Toast.makeText( getApplicationContext(),
items[which] + " Checked-" + Boolean.toString(isChecked),
Toast.LENGTH_SHORT).show();
}
});

AlertDialog alert = builder.create();
alert.show();

 

6. ProgressDialog type

 

 

private class ProgressDialogStop extends Thread
{
private final int mWaitTime = 3000;
private ProgressDialog dialog = null;

public ProgressDialogStop(ProgressDialog dialog) {
// TODO Auto-generated constructor stub
this.dialog = dialog;
}

@Override
public void run() {

int iWait = 0;
try
{
while( iWait < mWaitTime )
{
this.sleep(100);
iWait += 100;
}
}catch(Exception e)
{
//
}

this.dialog.dismiss();
super.run();
}
}

ProgressDialog dialog = ProgressDialog.show(AlertDialogTest.this, "",
"Loading. Please wait...", true);

Thread ProgressDialogStopThread = new ProgressDialogStop( dialog );
ProgressDialogStopThread.start();



7. ProgressBar type

 

 

private class ProgressBarStop extends Thread
{
private final int mWaitTime = 100;
private ProgressDialog progressDialog = null;

public ProgressBarStop(ProgressDialog progressDialog) {
// TODO Auto-generated constructor stub
this.progressDialog = progressDialog;
}

@Override
public void run() {

super.run();

// this.progressDialog.show(); // << 여기서 호출하면 Error 발생한다.

int iWait = 0;
try
{
while( iWait < mWaitTime )
{
this.sleep(100);
iWait++;
Log.i(LOGTAG, Integer.toString(iWait));
progressDialog.setProgress( iWait );
}
}catch(Exception e)
{
Log.i(LOGTAG, e.getMessage());
}

this.progressDialog.dismiss();
}
}

ProgressDialog progressDialog = null;
progressDialog = new ProgressDialog( AlertDialogTest.this );
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Loading...");
progressDialog.setMax(100);
progressDialog.setCancelable(true);

progressDialog.setButton("Btn1", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Toast.makeText( getApplicationContext(),
"Btn Click - " + Integer.toString(which),
Toast.LENGTH_SHORT).show();
}
});

progressDialog.setButton2("Btn2", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Toast.makeText( getApplicationContext(),
"Btn 2 Click - " + Integer.toString(which),
Toast.LENGTH_SHORT).show();
}
});

progressDialog.show();

Thread PrgrsBarStop = new ProgressBarStop( progressDialog );
PrgrsBarStop.start();



8. CustomDialog type

 

 

별도 Dialog 타입 Layout을 설정해야 한다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_width="200dip">

<TextView
android:id="@+id/TextView01"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textStyle="bold"
android:layout_width="wrap_content"
android:text=" AndroidPeople.com"/>

<TextView
android:id="@+id/TextView02"
android:layout_height="wrap_content"
android:textColor="#fff"
android:layout_width="wrap_content"
android:layout_margin="7dip"
android:text="Custom Dialog Example By AndroidPeople.com"
android:gravity="center"/>

<Button
android:id="@+id/OkButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
/>
</LinearLayout>

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
//http://about-android.blogspot.com/2010/02/create-custom-dialog.html


public class MyCustomDialog extends Dialog {

public MyCustomDialog(Context context) {
super(context);
this.setContentView(R.layout.custom_dialog);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

Button btn = (Button)findViewById(R.id.OkButton);
btn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
dismiss();
}
});
}
}

Dialog dialog = new MyCustomDialog(this);

dialog.show();


 

9. CustomDialog type 2

위 8번 내용을 그대로 사용.

 



AlertDialog.Builder md = new AlertDialog.Builder(this);
LayoutInflater contents = LayoutInflater.from(this);
View customView = contents.inflate(R.layout.custom_dialog, null);

Button btn = (Button)customView.findViewById(R.id.OkButton);
btn.setVisibility(View.INVISIBLE);

md.setPositiveButton("Positive", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
}
});

md.setNegativeButton("Negative", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
}
});

md.setNeutralButton("Neutral", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
}
});

md.setView( customView );
md.show();



기본 참고 베이스에 적절히 응용하거나, 추가해서 쓰신다면 더 예쁘고 좋은 다이얼로그 만드실수 있을 겁니다.

 

 

 

 

 

728x90
Posted by 정망스
,

상속과 다형성

C++ 2013. 9. 27. 23:46
728x90



상속(Inheritance)은 기존의 클래스를 토대로 해서 새로운 클래스를 만드는 방법입니다.


figure 클래스에서 상속을받아 Triangle, Square, Circle의 새로운 클래스를 만들어 내는 것입니다.


여기서 figure 클래스는 일명 부모클래스가 되며, Triangle, Square, Cirecle 클래스자식클래스가 됩니다.


상속의 개념은 이렇게 재사용성(Reusability)을 더해주기 때문에 기존에 만들어둔 클래스를 재사용해서 새로운 클래스를 쉽게 만들 수 있습니다.


다형성은 전구를 예로들어 처음엔 둥그런 백열 전구를 만들다가 생산 방식을 조금 바꿔 삼파장 램프를 생산하였습니다.


하지만 이 두가지 램프들은 소켓에 끼워지는 부분이 동일하게 만들어집니다. 


즉 모양은 바뀌었지만 부품과 부품을 연결하는 부분이 서로 약속되어 그대로 유지 되기 때문에 얼마든지 다른 종류의 부품으로 갈아 끼울 수 있게 됩니다.


이렇게 객체와 객체가 서로 약속한 부분 즉 인터페이스만 그대로 유지 된다면 얼마든지 다른 객체로 갈아 끼울 수 있다는 것입니다.


figure 객체에서 draw()라는 약속한 부분을 통해서 삼각형, 사각형, 원을 그릴수 있게 되는겁니다.


이것이 바로 다형성입니다.




728x90
Posted by 정망스
,
728x90



정보 은닉(Data Hiding)은 말그대로 정보를 숨긴다는 의미입니다. 

자동차의 타이어를 만드는 공장에서 핸들이 어떤 기술을 사용해서 만들어지는지 몰라도 된다는 것입니다.


객체로 말하면 다른 객체가 어떻게 구현되었는지 몰라도 된다는 것


좀 더 능동적으로 보자면 다른 객체의 내부 구현을 몰라도 된다는 것에 그치는것이 아니라. 다른 객체의 내부 구현을 반드시 몰라야 한다고 강요하는것입니다. 그래서 정보 무관심이 아니라 정보 은닉 이라고 합니다.



객체 A는 내부적인 사정으로 인해서 객체 B에게 본래 100바이트를 넘겨주는것이 약속이었지만 108바이트를 넘겨 주고 있었다.


객체 B는 객체 A에 대해서 여분의 8바이트가 더 오는것을 확인하고 계속해서 108바이트를 사용했다.


객체 A는 소스 코드를 수정하여 다시 100바이트를 넘겨 주었다.


객체 B는 여분의 8바이트가 사라져버려서 문제를 일으키게 된다.


이것이 바로 정보 은닉의 필요성입니다. 객체 B가 객체 A에대해 약속한 범위를 넘어서 버리는 오히려 아는것이 더 많아서 다쳐버렸습니다.


결국 정보 은닉은 서로 약속되어 있는 부분이 아니라면 보여주지도 말고 보지도 말자 라는 것입니다.


캡슐화(Encapsulation)은 텔레비젼 속에는 많은 전기 장치들이 들어있지만 케이스로 둘러 쌓여있어 보이지 않습니다.

보이는 것은 화면과 단추 뿐입니다. (여기서 화면과 단추는 텔레비전과 사용자간의 약속입니다.)


이렇게 약속된 부분을 제외한 나머지 부분을 감싸서 숨겨버리는 것을 캡슐화라고 합니다.


캡슐화를 사용해서 정보 은닉을 달성할수 있고. 객체간에 약속한 부분만이 드러나고 나머지 부분은 캡슐로 감싸서 다른 객체가 볼 수 없게 만드는 것입니다.


하지만 C++에서는 정보 은닉이나 캡슐화에 1:1로 매치되는 기능은 가지고 있지 않습니다.

하지만 클래스에 멤버 변수나 함수를 정의하면서 그 멤버를 외부에 보이게 할지 여부를 지정할 수 있습니다.

다른 객체와 약속된 부분이라면 외부에 보이게 저장하고, 아니라면 외부에 보이지 않게 지정하면 됩니다.


이렇게 함으로써 정보 은닉이나 캡슐화가 지향하는 목표를 상당부분 달성 할 수 있습니다.




728x90
Posted by 정망스
,
728x90

C++에서 기본적으로 제공되는 표준 라이브러리에는.. 아래 모양처럼 헤더파일을 추가합니다.


#include <iostream>

#include <string>

#include <cmath>

.

.

.




저희가 직접 만드는 헤더 파일은 아래와 같이 헤더파일 추가합니다.


#include "make.h"


차이점이 보이시나요..? 바로 <> " "의 차이입니다.


이 두 가지의 차이점은 헤더 파일을 찾는 위치에 있습니다.


<> : 표준 라이브러리의 헤더파일이 위치한 폴더에서 파일을 찾는다.

(비쥬얼 스튜디오를 사용하는 경우에는 비쥬얼 스튜디오를 설치한 폴더 안에 헤더 파일들이 위치한 폴더가 존재하는데 <>는 이곳에서 헤더 파일을 찾게 됩니다.)


" " : 현재 소스 파일이 있는 위치에서 찾는다.

(make.cpp에서 " "로 된 헤더파일을 직접 포함했다면. make.cpp가 존재하는 폴더에서 헤더 파일을 찾게 됩니다.)






728x90

'C++' 카테고리의 다른 글

이클립스 C++ 환경 구축  (0) 2013.10.05
상속과 다형성  (0) 2013.09.27
정보은닉(Data Hiding)과 캡슐화(Encapsulation)  (0) 2013.09.02
클래스와 객체..?  (0) 2013.08.31
#ifdef 와 #ifndef의 기능 (#define.... #endif)  (0) 2013.08.31
Posted by 정망스
,

클래스와 객체..?

C++ 2013. 8. 31. 00:13
728x90



클래스객체를 이 퍼즐조각에 비유할수 있을 것 같습니다.


변수나, 함수나 이러한 틀이 잡혀있는 퍼즐조각과도 같은 클래스들을 잘 사용해서 퍼즐의 완성품과도 같은 객체를 만들어내는 것입니다.


클래스는 구조체와 같은 개념이긴 한데 다른점은 함수까지도 클래스는 멤버로 넣어서 사용할수 있다는 점입니다.


물론 클래스 또한 사용자 정의 타입을 만들수 있고, 클래스를 타입으로 사용해서 정의한 변수들은 해당 클래스의 객체가 됩니다.




퍼즐이라는 클래스가 정의되어 있고 이 퍼즐을 타입으로 이용해서 puz1, puz2라는 객체를 만들었습니다.


이 각 객체들은 퍼즐 클래스에 있는 멤버들, 즉 변수나 함수들을 사용할수 있게됩니다.


ps. 구조체는 함수를 가질 수 없다?

X


C++에서는 구조체도 함수를 멤버로 가질 수 있다고 합니다. 하지만 그렇게 사용하지 않는 것이 일반적이라고 합니다. 


왜냐하면 C에서의 구조체는 변수만을 멤버로 가질 수 있었기 때문에 C로부터 이어져 온 관습이라고도 하고, C 소스 코드와의 호환성을 위한 것이라고도 합니다. 


어쨋든 이러한 이유 때문에 구조체에 함수를 멤버로 넣는 일은 흔치 않다고 합니다.




728x90
Posted by 정망스
,


맨 위로
홈으로 ▲위로 ▼아래로 ♥댓글쓰기 새로고침