2012-04-11 2 views
0

Я делаю три вкладки.Tab change listner in android

Язык. (Включает язык класса с языковой раскладкой) активации (Include активации класса с макетом АКТИВИРУЙТЕ) Settings (Включить настройки класса с установкой макета)

В списке параметров, если я изменить настройки, чтобы скрыть определение слов в макете языка. И снова нажмите на язык перевода языка перевода.

Я думаю, что мне нужно подать заявку на вкладке change listner.

Но что я должен делать на вкладке change listner.

Это моя 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

Когда мы меняем вкладки по методу Возобновления? –

+0

да, это называется, когда активность выходит на передний план – candyleung

+0

спасибо. он работает –

1

Вам просто нужно overide onResume() в языковой деятельности и проверьте изменения параметров и, если так можно поставить логику в скрыть перевод.

onResume будет вызываться, когда пользовательский ввод собирается на операцию так,

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

} 

Вы также можете реализовать метод OnPause().

+0

спасибо .. это работает –