dystroy 2013-02-26 05:29 采纳率: 80%
浏览 3641
已采纳

android tab 变换监听器

我创建了三个Tab.
Language (包括language 布局的language 类) Activation (包括Activation 布局的Activation类) Settings (包括Settings 布局的Settings 类)
在 settings 列表里改变 settings 可以隐藏language布局中的文字定义,然后再次点击language Tab的时候,文字翻译仍然还在。
我认为应该设置一个tab 变换监听器。
但是怎么实现tab变换监听器呢?
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);
                }
                }

            }
        });
    }
}
  • 写回答

2条回答 默认 最新

  • Baby_Bonnie 2013-02-26 06:11
    关注

    在 Language's onResume() 添加以下代码:

    @Override
    protected void onResume()
    {
        super.onResume();
        if (Constants.TAGS_ENABLE == true) {
            // set visibility...
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机