tab을 이용한 어플을 개발중인데 막히는 부분이 있어 질문 드립니다.
두개의 tab이 존재하는데 tab을 클릭 하였을때는 Activity를 이동하여 setContent에 뿌려주어 각각 뿌려줍니다.
두개다 ListView를 구현한 Activity를 뿌려주는데 그 LIst에 아이템을 클릭하였을때 다른 Activity로 이동을 합니다.
여기서 View가 Tab을 계속 가지고 있어야 하는데.. 방법이 떠오르지 않네요..
tab.java
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent1,intent2;
intent1 = new Intent().setClass(this, BasicList.class);
intent2 = new Intent().setClass(this, CountryList.class);
spec = tabHost.newTabSpec("basic")
.setIndicator("기본 매너")
.setContent(intent1);
tabHost.addTab(spec);
spec = tabHost.newTabSpec("country")
.setIndicator("나라별 매너")
.setContent(intent2);
tabHost.addTab(spec);
---------------------------------------------------------------------------------------------------------------------------
list.java
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(this,MannerDetail.class);
Bundle b = new Bundle();
b.putInt("position", position);
intent.putExtra("list", list);
intent.putExtras(b);
startActivity(intent);
}
이 리스트 클릭 시 Activity를 이동하면서 Tab을 유지 하고 싶습니다..
감사합니다.
일단 Tab이 들어가는 모든 Activity들을 Tab에 추가 시킵니다.
꼭 Indicator가 들어가야 하는 Activity들을 제외하고 나머지의 Indicator는 Visibility를 GONE으로 하구요.
리스트 클릭 이벤트에서
Tab Activity쪽으로 인텐트를 보냅니다. 미리 정해놓은 액션을 보내는거죠.
그리고 extra 영역에 내가 이동할 tab의 index (Tab에 추가된 인덱스입니다.)를 같이 보냅니다.
이걸 받은 Tab Activity는 currentTab을 바꿔주는거죠.
그리고 tab focus까지 제대로 마무리하면 감쪽같이 됩니다.
뒤로가기는 따로 구현할 수도 있겠으나...
앵간하면 그냥 앞으로 가는걸로 눈속임 하세요.