마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

텝메뉴새로고침질문드립니다.

0 추천

 

 

안녕하세요~^^ 안드로이드 입분10일차 입니다.

텝메뉴마다 웹뷰링크를걸었는데 텝메뉴이동시 엑티비티를 새로고침하고싶습니다.

자바책을사서 열씸히 공부중이지만 당장 어플을완성해야해서 거의7일째 3시간씩 잠을청하며 열공을하고있어요~

아래는 해당텝메뉴소스입니다. 해당코드부분을 자세하게  알려주시면 감사하겠습니다. 

많이고민하다 질문올립니다.~ 급하게 목적만해결하고싶은 마음은 조금도없어요 근데 주위의압박으로 당장완성을해야해서

부탁좀드릴꼐요~!!화이팅~!!

package com.superface;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.TabHost;

public class MainTab extends TabActivity implements
OnCheckedChangeListener {
	
	//Define 1 tab host that will host four tabs
	private TabHost tabHost;
	
	//Define the intents to be activated when user want to change the tab
    private Intent tab1Intent;
    private Intent tab2Intent;
    private Intent tab3Intent;
    private Intent tab4Intent;
    private Intent tab5Intent;
   
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //Window with no title bar, You can remove in your project if you like Title tab
       requestWindowFeature(Window.FEATURE_NO_TITLE);
      
    
        setContentView(R.layout.tabs);         
        
       
        
        //Set the layout of this activity. The tabs are defined there.
        
        
         //Initialize intents, Change it in your app with your Class names.
        this.tab1Intent = new Intent(this, FirstActivity.class); //Intent triger when users clicks on first tab
        this.tab2Intent = new Intent(this, SecondActivity.class);//Intent triger when users clicks on second tab
        this.tab3Intent = new Intent(this, ThirdActivity.class);//Intent triger when users clicks on third tab
        this.tab4Intent = new Intent(this, FourthActivity.class);//Intent triger when users clicks on fourth tab
        this.tab5Intent = new Intent(this, fiveActivity.class);//Intent triger when users clicks on fourth tab
        //Initialize the radio buttons that represent tab changer button
        //This buttons are defined in the layout file main.xml in the layout folder
        ((RadioButton) findViewById(R.id.rb1)).setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.rb2)).setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.rb3)).setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.rb4)).setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.rb5)).setOnCheckedChangeListener(this);
        
        
        
       
        //Now setup the TabHost, get TabHost From the activity
        this.tabHost=getTabHost();
        
        //Now initialize the tabs
        //Look at buildTabs() method bellow for information about parameters  
        this.tabHost.addTab(buildTabs("first_tab", R.string.tab_1_title,
                R.drawable.place_unselected, this.tab1Intent));

        this.tabHost.addTab(buildTabs("second_tab", R.string.tab_2_title,
                R.drawable.favorite_unselected, this.tab2Intent));

        this.tabHost.addTab(buildTabs("third_tab", R.string.tab_3_title,
                R.drawable.group_unselected, this.tab3Intent));

        this.tabHost.addTab(buildTabs("fourth_tab", R.string.tab_4_title,
                R.drawable.user_unselected, this.tab4Intent));
        this.tabHost.addTab(buildTabs("five_tab", R.string.tab_5_title,
                R.drawable.user_unselected, this.tab5Intent));
    }
    
  
    
    /**
     * @description
     * Create the Tab host specific button specification like: tag, image and intent
     * @param tag A simple string that will identify this tab
     * @param resLabel The label of this tab, Ex "Home"
     * @param resIcon The icon of this tab, It must be local resource id number, Ex R.drawable.something
     * @param content The intent for this tab
     * @return TabHost.TabSpec
     */
    private TabHost.TabSpec buildTabs(String tag, int resLabel, int resIcon,
            final Intent content) {
        return this.tabHost
                .newTabSpec(tag)
                .setIndicator(getString(resLabel),
                        getResources().getDrawable(resIcon))
                .setContent(content);
    }

	@Override
	/**
	 * Trigered when users clicks on the tab
	 */
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		
		// TODO Auto-generated method stub
		if (isChecked) {
            switch (buttonView.getId()) {
            case R.id.rb1:   	
                this.tabHost.setCurrentTabByTag("first_tab");
                break;
            case R.id.rb2:
                this.tabHost.setCurrentTabByTag("second_tab");
                break;
            case R.id.rb3:
                this.tabHost.setCurrentTabByTag("third_tab");
                break;
            case R.id.rb4:
                this.tabHost.setCurrentTabByTag("fourth_tab");
                break;
            case R.id.rb5:
                this.tabHost.setCurrentTabByTag("five_tab");
                break;
            }
        }
	}
}

 

바나로이 (140 포인트) 님이 2013년 4월 17일 질문

1개의 답변

0 추천
1. static Handler를 이용하는 방법있습니다.

각 액티비티 마다 static Handler를 만드시고

탭 액티비티에 해당 핸들러를 등록합니다.

그리고 탭 액티비티에서는 탭 호스트에 onTabChangeListener를 등록하여

탭 이동시 해당 핸들러로 새로고침하라는 메시지를 전달하면 되겠네요.

 

2. 브로드캐스트를 이용하는 방법이 있습니다.

커스텀 브로드캐스트를 만드셔서 각 액티비티마다 다른 브로드캐스트 리시버를 등록하시고

탭 이동시 그에 맞는 브로드캐스트를 날려주면 될 것 같네요.
원조안드로이드 (58,190 포인트) 님이 2013년 4월 18일 답변
...