-. 백그라운드 스레드를 사용해 해당작업 처리.
  -. 완료시점 setMax()로 지정, setProgress()로 진행상황 설정(진행상태 확인 getProcess())
  -. 종료시점 명확하지 않을경우 setIndeterminate() 메소드 값 true로 넘겨줌 
    => 진행 상황에 관계없이 계속해서 작업 중이라고 표현.
# 탭(Tab) 기본 예제
  -. main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TabHost android:id="@+id/tabhost"
		android:layout_width="fill_parent"
		android:layout_height="fill_parent">
		<TabWidget android:id="@android:id/tabs"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
		/>
		<FrameLayout android:id="@android:id/tabcontent"
			android:layout_width="fill_parent"
			android:layout_height="fill_parent"
			android:paddingTop="62px">
			<AnalogClock android:id="@+id/tab1"
				android:layout_width="fill_parent"
				android:layout_height="fill_parent"
				android:layout_centerHorizontal="true"
			/>
			<Button android:id="@+id/tab2"
				android:layout_width="fill_parent"
				android:layout_height="fill_parent"
				android:text="단순한 버튼"
			/>
		</FrameLayout>
	</TabHost>
</LinearLayout>
  -. source
package my.app;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TabHost;
public class Tab extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TabHost tabs = (TabHost) findViewById(R.id.tabhost);
        tabs.setup();
        // 탭을 사용하기전 반드시 TabHost 인스턴스의 setup()을 호출해얗란다.
        TabHost.TabSpec spec = tabs.newTabSpec("tag1");
        spec.setContent(R.id.tab1);		// 내용 불러옴
        spec.setIndicator("시계");		// 탭 글자
        tabs.addTab(spec);				// 내용 추가
        spec = tabs.newTabSpec("tag2");
        spec.setContent(R.id.tab2);
        spec.setIndicator("버튼");
        tabs.addTab(spec);
        tabs.setCurrentTab(0);			// 기본적으로 표시할 탭
    }
}
# 동적으로 탭 생성
  -. main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TabHost android:id="@+id/tabhost"
		android:layout_width="fill_parent"
		android:layout_height="fill_parent">
		<TabWidget android:id="@android:id/tabs"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
		/>
		<FrameLayout android:id="@android:id/tabcontent"
			android:layout_width="fill_parent"
			android:layout_height="fill_parent"
			android:paddingTop="64px">
			<Button android:id="@+id/buttontab"
				android:layout_width="fill_parent"
				android:layout_height="fill_parent"
				android:text="단순한 버튼"
			/>
		</FrameLayout>
	</TabHost>
</LinearLayout>
   -. source
package my.app;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AnalogClock;
import android.widget.Button;
import android.widget.TabHost;
public class Tab extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final TabHost tabs = (TabHost) findViewById(R.id.tabhost);
        tabs.setup();
        // 탭을 사용하기전 반드시 TabHost 인스턴스의 setup()을 호출해야한다.
        TabHost.TabSpec spec = tabs.newTabSpec("buttontab");
        spec.setContent(R.id.buttontab);
        spec.setIndicator("버튼");
        tabs.addTab(spec);
        tabs.setCurrentTab(0);
        Button btn = (Button)tabs.getCurrentView().findViewById(R.id.buttontab);
        btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				TabHost.TabSpec spec = tabs.newTabSpec("시계");
				// 해당하는 탭 내용에 들어갈 위젯 생성하는 기능
				spec.setContent(new TabHost.TabContentFactory() {
					@Override
					public View createTabContent(String tag) {
						return (new AnalogClock(Tab.this));
					}
				});
				spec.setIndicator("시계");
				tabs.addTab(spec);
			}
		});
    }
}
댓글 없음:
댓글 쓰기