2012-04-11 18 views
0

私は3つのタブを作成します。アンドロイドのタブ変更リスナー

言語。(言語レイアウトと言語のクラスを含める) アクティベーション(アクティブレイアウトでアクティベーションクラスを含める) 設定(レイアウト設定で設定クラスを含める)

設定リストでは、私は非表示にするには、設定を変更した場合言語レイアウトにおける単語の定義。 そしてまだそこにあるタブ言語の翻訳をもう一度クリックしてください。

私はここでタブ変更リスナーに適用する必要があると思います。

しかし、私はタブ変更リスナーで何をすべきですか?

これは私のTabActivityです。

package com.languagetranslate; 

import com.languagetranslate.Constants.Constants; 
import com.languagetranslate.dao.UserData; 

import android.app.Activity; 
import android.app.TabActivity; 
import android.content.Context; 
import android.content.Intent; 
import android.content.res.Resources; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.widget.FrameLayout; 
import android.widget.ListView; 
import android.widget.RelativeLayout; 
import android.widget.TabHost; 
import android.widget.TextView; 
import android.widget.TabHost.OnTabChangeListener; 

public class Screen1 extends TabActivity { 

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

     initializeTabs(); 
    } 

    private void initializeTabs() { 
     TabHost tabHost = getTabHost(); // The activity TabHost 
     TabHost.TabSpec spec; // Resusable TabSpec for each tab 
     Intent intent; // Reusable Intent for each tab 

     // Create an Intent to launch an Activity for the tab (to be reused) 
     intent = new Intent().setClass(this, WordsClass.class); 

     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabHost.newTabSpec("Words").setIndicator("Words") 
       .setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same for the other tabs 
     intent = new Intent().setClass(this, ActivateClass.class); 
     spec = tabHost.newTabSpec("Activitation").setIndicator("Activitation") 
       .setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same for the other tabs 
     intent = new Intent().setClass(this, Settings.class); 
     spec = tabHost.newTabSpec("Settings").setIndicator(".\n.\n.") 
       .setContent(intent); 
     tabHost.addTab(spec); 

     tabHost.setCurrentTab(2); 


     tabHost.setOnTabChangedListener(new OnTabChangeListener() { 

      public void onTabChanged(String tabId) { 

       if (tabId == "Language"){ 

        Constants.TAGS_ENABLE = UserData.getTagSettings(getApplicationContext(), 
          Constants.SETTINGS_FILE); 
        if (Constants.TAGS_ENABLE == true) { 
         LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
         FrameLayout item = (FrameLayout)findViewById(android.R.id.tabcontent); 
         View child = inflate.inflate(R.layout.wordlayout, null); 
          child.findViewById(R.id.availabletags).setVisibility(View.VISIBLE); 
          child.findViewById(R.id.tags).setVisibility(View.VISIBLE); 

          item.addView(child); 
//      
//      ((TextView) findViewById(R.id.availabletags)) 
//        .setVisibility(View.VISIBLE); 
//      ((ListView) findViewById(R.id.tags)) 
//        .setVisibility(View.VISIBLE); 

        } 

       } 


      } 
     }); 
    } 
} 

答えて

3

多分あなたは言語のonResume()でそれらを置くことができます。

@Override 
protected void onResume() 
{ 
    super.onResume(); 
    if (Constants.TAGS_ENABLE == true) { 
     // set visibility... 
    } 
} 
+0

Resumeメソッドのタブを変更すると、 –

+0

はい、アクティビティがフォアグラウンドに来るときに呼び出されます – candyleung

+0

ありがとうございます。それは動作します –

1

は、あなただけの言語活動にonResume()をオーバライドし、変更した設定をチェックし、もしそうなら、あなたがロジックにまでを置くことができますする必要があります翻訳を隠す。ユーザ入力がとても活動に起こっているときonResumeが呼び出されます

protected void onResume() 
{ 
super.onResume(); 
if(settings_changed) 
//logic here 

} 

はまた、onPause()メソッドを実装する必要があります。

+0

ありがとう..それは動作します –

関連する問題