위와 같이 탑에 메뉴를 넣기 원한다면, 아래와 같이 사용해 보면 좋을거 같습니다.

onCreate() 에 선언
mainTabListenerOn(); // menuMain1 이미지 버튼 5개에 관한 클래스

버튼 이름은 mainMenu1 , 2,3,4...
inculde 이름은 Main_menu1,2,3,4....
간단하게 처리가능합니다. :)
...
버튼 클릭시 이벤트
public void mainTabListenerOn() {
        findViewById(R.id.mainMenu1).setOnClickListener(
                new ImageButton.OnClickListener() {
                    public void onClick(View v) {
                        mainContentToggle(v);
                    }
                });
        findViewById(R.id.mainMenu2).setOnClickListener(
                new ImageButton.OnClickListener() {
                    public void onClick(View v) {
                        mainContentToggle(v);
                    }
                });
        findViewById(R.id.mainMenu3).setOnClickListener(
                new ImageButton.OnClickListener() {
                    public void onClick(View v) {
                        mainContentToggle(v);
                    }
                });
        findViewById(R.id.mainMenu4).setOnClickListener(
                new ImageButton.OnClickListener() {
                    public void onClick(View v) {
                        mainContentToggle(v);
                    }
                });
        findViewById(R.id.mainMenu5).setOnClickListener(
                new ImageButton.OnClickListener() {
                    public void onClick(View v) {
                        mainContentToggle(v);
                    }
                });
    }

public void mainContentToggle(View v) {

        findViewById(R.id.main_tab1).setVisibility(View.INVISIBLE);
        findViewById(R.id.main_tab2).setVisibility(View.INVISIBLE);
        findViewById(R.id.main_tab3).setVisibility(View.INVISIBLE);
        findViewById(R.id.main_tab4).setVisibility(View.INVISIBLE);
        findViewById(R.id.main_tab5).setVisibility(View.INVISIBLE);

        if (v.getId() == R.id.mainMenu2) {
            findViewById(R.id.main_tab2).setVisibility(View.VISIBLE);
        } else if (v.getId() == R.id.mainMenu3) {
            findViewById(R.id.main_tab3).setVisibility(View.VISIBLE);
        } else if (v.getId() == R.id.mainMenu4) {
            findViewById(R.id.main_tab4).setVisibility(View.VISIBLE);
        } else if (v.getId() == R.id.mainMenu5) {
            findViewById(R.id.main_tab5).setVisibility(View.VISIBLE);
        } else {
            findViewById(R.id.main_tab1).setVisibility(View.VISIBLE);
        }

        findViewById(R.id.mainMenu1).setBackgroundResource(
                R.drawable.category_menu1_off);
        findViewById(R.id.mainMenu2).setBackgroundResource(
                R.drawable.category_menu2_off);
        findViewById(R.id.mainMenu3).setBackgroundResource(
                R.drawable.category_menu3_off);
        findViewById(R.id.mainMenu4).setBackgroundResource(
                R.drawable.category_menu4_off);
        findViewById(R.id.mainMenu5).setBackgroundResource(
                R.drawable.category_menu5_off);


        if (v.getId() == R.id.mainMenu2)
            v.setBackgroundResource(R.drawable.category_menu2_on);
        else if (v.getId() == R.id.mainMenu3)
            v.setBackgroundResource(R.drawable.category_menu3_on);
        else if (v.getId() == R.id.mainMenu4)
            v.setBackgroundResource(R.drawable.category_menu4_on);
        else if (v.getId() == R.id.mainMenu5)
            v.setBackgroundResource(R.drawable.category_menu5_on);
        else
            v.setBackgroundResource(R.drawable.category_menu1_on);

    }

main.xml
<LinearLayout android:layout_width="fill_parent"
            android:layout_height="34dip" xmlns:android="http://schemas.android.com/apk/res/android"
            android:textColor="#FFFFFF" android:layout_marginTop="-5px"
            android:background="@drawable/cartoon_viewpage_bg_tit"
            android:layout_gravity="center_vertical|center_horizontal"
            >

            <Button android:id="@+id/mainMenu1"
            android:layout_width="100px"
            android:layout_height="wrap_content" android:background="@drawable/category_menu1_off"
            android:layout_weight="1"
            android:layout_gravity="center_vertical"
            />
       
           
            <Button android:id="@+id/mainMenu2"
            android:layout_width="100px"
            android:layout_height="wrap_content" android:background="@drawable/category_menu2_off"
            android:layout_weight="1"
            android:layout_gravity="center_vertical"
            />
           
       
            <Button android:id="@+id/mainMenu3"
            android:layout_width="100px"
            android:layout_height="wrap_content" android:background="@drawable/category_menu3_off"
            android:layout_weight="1"
            android:layout_gravity="center_vertical"
            />
           
       
           
            <Button android:id="@+id/mainMenu4"
            android:layout_width="100px"
            android:layout_height="wrap_content" android:background="@drawable/category_menu4_off"
            android:layout_weight="1"
            android:layout_gravity="center_vertical"/>
           
       
           
            <Button android:id="@+id/mainMenu5"
            android:layout_width="100px"
            android:layout_height="wrap_content" android:background="@drawable/category_menu5_off"
            android:layout_weight="1"
            android:layout_gravity="center_vertical"
            />
           
       

        </LinearLayout>


        <FrameLayout android:layout_below="@+id/mainLayoutFrame"
            android:id="@+id/mainLayoutContent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
        >
            <include layout="@layout/main_tab1"
                android:id="@+id/main_tab1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
            <include layout="@layout/main_tab2"
                android:id="@+id/main_tab2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:visibility="invisible"/>
            <include layout="@layout/main_tab3"
                android:id="@+id/main_tab3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:visibility="invisible"/>
            <include layout="@layout/main_tab4"
                android:id="@+id/main_tab4"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:visibility="invisible" />
            <include layout="@layout/main_tab5"
                android:id="@+id/main_tab5"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:visibility="invisible" />
        </FrameLayout>

main_tab1 , 2, 3, 4, 5  . xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
 
     <TextView android:id="@+id/main_menu2" android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textSize="40px"
            android:text="메인 탭 2"
            android:textColor="#FFFFFF" android:gravity="center"
            android:drawablePadding="10px"
            android:textStyle="bold" android:duplicateParentState="false" />
       
</LinearLayout>

Posted by 예배하는 프로그래머
  
탭 밑에 라인을 tabStrip 라고 부른다.

TabWidget
 android:tabStripEnabled="false"

단 sdk 8 부터 적용이 된다. 유의하자!
Posted by 예배하는 프로그래머
  
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="70px"
android:gravity="center"
/>
Posted by 예배하는 프로그래머
  
public class Intro extends Activity {
    Handler myHandler = new Handler();
    Runnable myRunnable = new Runnable() {

    public void run() {
        Intent i = new Intent(Intro.this, Host.class);
        overridePendingTransition(R.anim.fade, R.anim.hold);
        i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        Intro.this.startActivity(i);
        finish(); - 백했을경우 닫아 버리기
        // overridePendingTransition(0,0);
        // startActivity(new Intent(IntroActivity.this, netturn.class));
        }
    };

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.intro);

       
   
        myHandler.postDelayed(myRunnable, 3000); // 딜레이 지정

    }

    public boolean onKeyDown(int keyCode, KeyEvent e) {
    Log.v(null, "" + keyCode);
            if (keyCode == KeyEvent.KEYCODE_BACK) {
            }
        return false;
    }
    public boolean onKeyDown1(int keyCode, KeyEvent e) {
    Log.v(null, "" + keyCode);
        if (keyCode == KeyEvent.KEYCODE_HOME) {
        myHandler.removeCallbacks(myRunnable);
        }
    return false;
    }
}
Posted by 예배하는 프로그래머
  
protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
       
       
        setContentView(R.layout.host);               

        tabHost = getTabHost();
        tabHost.setOnTabChangedListener(this);

        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("",getResources().getDrawable(R.drawable.tab_menu1_off))
                .setContent(new Intent(this, PhotoSwitcher.class)));
      
        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("",getResources().getDrawable(R.drawable.tab_menu2_off))               
                .setContent(new Intent(this, PhotoSwitcher.class)));
       
        tabHost.addTab(tabHost.newTabSpec("tab3")
                .setIndicator("",getResources().getDrawable(R.drawable.tab_menu3_off))
                .setContent(new Intent(this, PhotoSwitcher.class)));

        tabHost.addTab(tabHost.newTabSpec("tab4")
                .setIndicator("",getResources().getDrawable(R.drawable.tab_menu4_off))
            //   .setIndicator("스타",getResources().getDrawable(R.drawable.tab_menu4_off)) - 택스트 넣기
                .setContent(new Intent(this, PhotoSwitcher.class)));

tabHost.setCurrentTab(0); - 탭 1 상태 초기
       
    }

    @Override
    public void onTabChanged(String tabId) {
        // TODO Auto-generated method stub
//  배경넣기//tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#7392B5"));
  
// 클릭할때 이미지 변경    
        int menu_off[] ={R.drawable.tab_menu1_off,R.drawable.tab_menu2_off,R.drawable.tab_menu3_off,R.drawable.tab_menu4_off};
        int menu_on[] = {R.drawable.tab_menu1_on,R.drawable.tab_menu2_on,R.drawable.tab_menu3_on,R.drawable.tab_menu4_on};
       
        for(int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
            iv = (ImageView)tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.icon);
            iv.setImageDrawable(getResources().getDrawable(menu_off[i]));
        }
            ip = (ImageView)tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).findViewById(android.R.id.icon);
            ip.setImageDrawable(getResources().getDrawable(menu_on[tabHost.getCurrentTab()]));
           

    }
Posted by 예배하는 프로그래머
  
AndroidMenifest.xml에 적용

Application 전체에 적용
application에 android:theme="@android:style/Theme.NoTitleBar" 삽입

<application 

android:icon="@drawable/icon" 

android:label="@string/app_name"

android:debuggable="true"

android:theme="@android:style/Theme.NoTitleBar"

>


특정 Activity 에 적용
activity에 android:theme="@android:style/Theme.NoTitleBar" 삽입

<activity 

android:name=".TestClass" 

android:label="@string/app_name"

android:theme="@android:style/Theme.NoTitleBar"

>

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>



Code에 적용

TestClass.java
setContentView() 보다 먼저 처리되야 한다.

import android.app.Ativity;

import android.os.Bundle;


public class TestClass extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.main);

}

}

Posted by 예배하는 프로그래머
  
    Log.d("111", this.getString(temp_id));

형변환

int temp = Integer.parseInt(a.getText().toString());
int.Parser()는 이렇게 사용하시면 됩니다.^^
혹은
int temp = Integer.valueOf(a.getText().toString());

Posted by 예배하는 프로그래머
  
package kr.co.mt;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Window;

/**
 * 초기화면
 *
 * @author joon
 *
 */
public class Intro extends Activity {
    Handler myHandler = new Handler();
    Runnable myRunnable = new Runnable() {

    public void run() {
        Intent i = new Intent(Intro.this, Host.class);
        overridePendingTransition(R.anim.fade, R.anim.hold);
        i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        Intro.this.startActivity(i);
        finish(); // 백 버튼 눌렀을 경우 어플 완전 종료
        // overridePendingTransition(0,0);
        // startActivity(new Intent(IntroActivity.this, netturn.class));
        }
    };

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.intro);
   
        myHandler.postDelayed(myRunnable, 3000); // 딜레이 지정

    }

    public boolean onKeyDown(int keyCode, KeyEvent e) {
    Log.v(null, "" + keyCode);
            if (keyCode == KeyEvent.KEYCODE_BACK) {
            }
        return false;
    }
    public boolean onKeyDown1(int keyCode, KeyEvent e) {
    Log.v(null, "" + keyCode);
        if (keyCode == KeyEvent.KEYCODE_HOME) {
        myHandler.removeCallbacks(myRunnable);
        }
    return false;
    }
}
Posted by 예배하는 프로그래머
  
private View header;
header = null;
       header = inflater.inflate(R.layout.header, null); // header.xml
g = (MyGallery) header.findViewById(R.id.gallery);
titlelistTxt = (TextView) header.findViewById(R.id.titlelistTxt);
layout = (LinearLayout) header.findViewById(R.id.dotPanel);

// list3 는 R.layout.main 
	list3.addHeaderView(header); 
// * addheaderview 는 단 한번만 실행이 되야 한다. 여러번 실행되어도 에러는 안나지만,
화면이 떨리거나, 위치가 엉뚱하게 붙기 때문이다.


list3.setAdapter(m_adapter3);

Posted by 예배하는 프로그래머
  

오른쪽과 같이 이미지와 listview 을 한개의 scroll 을 유지하려먼 addHeaderView 에 대해 알아야 한다.

addHeaderView 에 관해 구글서치 중에 좋은 블로그가 있어 담아두고 싶다. 여러군대 찾아 봣지만, 다들 어렵고 쉽게 소스 위주로 되어 있어 쉽게 이해할수 있을것이다. :)

링크 : http://www.samcoles.co.uk/mobile/android-listactivity-with-a-header-or-footer/

Android ListActivity with a header or footer

This post will show you how to go about implementing a ListActivity with a header or footer that does not follow the same layout as the list rows. A well known and obvious example of this is the main screen on the Android Market.

First, create a class that extends ListActivity:

ListWithHeader.java

1
2
3
4
5
6
7
8
9
10
11
12
13
package samcoles.listwithheader;
 
import android.app.ListActivity;
import android.os.Bundle;
 
public class ListWithHeader extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_main);
    }
}
ListWithHeader

Remember to ensure you have added this activity to your AndroidManifest.xml.

Next up you’ll need to create the list_main layout that’s set in the above ListActivity within /res/layout. Remember the <ListView> must have id=”@+id/android:list” and you should also have a view with id=”@+id/android:empty” to display when there’s no items in the list. Your ListActivity will go looking for these and your app will crash when loading this activity if you don’t have them. If you’re not aware of this then the debugger can be a bit unhelpful. The TextView uses a string resource, empty_list that you’ll need to remember to add too if you’re using this.

here’s the list_main layout:

list_main.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="utf-8"?>   
 
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">
  <ListView
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none"/>
  <TextView
    android:id="@+id/android:empty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/empty_list" />
</LinearLayout>

You’ll also need a layout for the header, note that this below references a couple of string resources and an image resource:

list_header.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/header_layout_root"
  android:background="#ffffff"
  android:orientation="vertical">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/app_name"
        android:background="#000000"
        android:textColor="#ffffff"
        android:textSize="28dp"
        android:gravity="center_horizontal"
        android:paddingTop="10dp"
        android:paddingBottom="10dp">
    </TextView>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/sample_image"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/sample_image"
            android:scaleType="fitXY">
        </ImageView>
        <TextView
            android:id="@+id/sample_title"
            android:text="@string/sample_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#ffffffff"
            android:textSize="12dp"
            android:background="#AA000000"
            android:padding="5dp"
            android:layout_alignParentLeft="true"
            android:layout_alignBottom="@id/sample_image">
        </TextView>
    </RelativeLayout>
</LinearLayout>

Next go back to your ListActivity class and it’s time to put in the code to add the header to your list, place this just below the call to setContentView():

1
2
3
4
ListView lv = getListView();
LayoutInflater inflater = getLayoutInflater();
View header = inflater.inflate(R.layout.list_header, (ViewGroup) findViewById(R.id.header_layout_root));
lv.addHeaderView(header, null, false);

To explain the above, first we call getListView() to get the activity’s ListView and assign this to an object. We then call getLayoutInflater() and do the same – this gets the LayoutInflater that’s attached to the current application context. The LayoutInflater is then used to instantiate the layout xml file so that we have a View object that, in line 4, we can attach to the ListView! There is also a method ListView.addFooterView() – you use this in exactly the same way as ListView.addHeaderView().

The full ListActivity class is shown below, it also puts some items in the list.

ListWithHeader.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package samcoles.listwithheader;
 
import android.app.ListActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
 
public class ListWithHeader extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_main);
 
        //add header to list
        ListView lv = getListView();
        LayoutInflater inflater = getLayoutInflater();
        View header = inflater.inflate(R.layout.list_header, (ViewGroup) findViewById(R.id.header_layout_root));
        lv.addHeaderView(header, null, false);
 
        //add some list items
        String listItems[] = {"List Item One", "List Item Two", "List Item Three", "List Item Four", "List Item Five"};
        lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems));
    }
}

And here’s a look at that in the emulator:

Posted by 예배하는 프로그래머