tabs-android tab 变换监听器

问题描述

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);
                }
                }

            }
        });
    }
}

解决方案

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

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

解决方案二:

在 language Activity 中重写 onResume(),检查更改设置。
当在 activity 中有用户输入时,onResume 会被调用。

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

}
时间: 2024-09-14 00:09:09

tabs-android tab 变换监听器的相关文章

Android Tab 控件详解及实例

Android Tab 控件详解及实例 在桌面应用中Tab控件使用得非常普遍,那么我们经常在Android中也见到以Tab进行布局的客户端.那么Android中的Tab是如何使用的呢? 1.Activity package com.wicresoft.activity; import com.wicresoft.myandroid.R; import android.app.TabActivity; import android.os.Bundle; import android.util.Lo

Android Tab标签的使用基础

Android程序中,Tab标签窗口是一种常用的UI界面元素.它的实现主要是利用了TabHost类. TabHost说明 TabHost是一个标签窗口的容器. 一个TabHost对象包含两个子元素对象: 一个对象是tab标签集合(TabWidget),用户点击它们来选择一个特定的标签: 另一个是FrameLayout对象,展示当前页的内容. 子元素通常是通过容器对象来控制,而不是直接设置子元素的值. 下面结合ApiDemos中的例子来说明TabHost的用法. 第一个Tab例子:使用TabAct

android tab切换效果如图???求实现思路

问题描述 android tab切换效果如图???求实现思路 解决方案 Android实现Tab切换效果总结 解决方案二: 其实这个效果分块解释,这样的效果不难.上面的四个按钮要做style,选择和非选择要有相应的图片背景就ok了. 解决方案三: 谢谢,我真正想问的是 上边 白色 和 灰色倾斜的的圆角只能用图片?? 解决方案四: 上边的白色和灰色,用图片实现比较快,而且方便.也可以做动画什么的. 解决方案五: 上边的是使用图片显示,下面使用Viewpager就行了.

android开发-android tab选项卡跳转activity的时候有点卡

问题描述 android tab选项卡跳转activity的时候有点卡 第一次加载的时候,比较卡,按另一个tab的时候,之前那个还在,要过一会儿才能跳转,导致我的两个tab看上去同时亮的,怎么优化

[Android]Tab

<?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_alignParentBottom="true" android:layout_w

Android编程之监听器的实现方法_Android

本文实例讲述了Android编程之监听器的实现方法.分享给大家供大家参考,具体如下: 1.通过内部类实现监听器,将事件监听器定义成当前的内部类,使用内部类可以在当前类中复用监听器. 第一步: 写监听器类,覆盖对应的抽象方法 第二步:创建监听器对象 第三步:注册 以一个button为例,代码如下: package cn.csdn.android.tesxt; import android.app.Activity; import android.content.DialogInterface; i

Android编程之监听器用法实例分析

本文实例讲述了Android编程之监听器用法.分享给大家供大家参考,具体如下: 这里通过监听内容提供者数据变化和监听发送短信进行讲解监听器.如果用户提供者数据发生了变化,监听器立刻就能收到对数据库操作的记录,而监听器是采用通知的机制,如果不采用通知的机制也可以做,那就是不断的查询数据库,这样的话效率就会很低.而采用通知机制的话,当用户向数据库发送一条记录,ContentObserver立刻就能获取到,我们就可以进行处理数据. 监听内容提供者数据的变化 1.在内容提供者中可以通知其他程序数据发生变

Android编程之监听器的实现方法

本文实例讲述了Android编程之监听器的实现方法.分享给大家供大家参考,具体如下: 1.通过内部类实现监听器,将事件监听器定义成当前的内部类,使用内部类可以在当前类中复用监听器. 第一步: 写监听器类,覆盖对应的抽象方法 第二步:创建监听器对象 第三步:注册 以一个button为例,代码如下: package cn.csdn.android.tesxt; import android.app.Activity; import android.content.DialogInterface; i

如何改变Android tab 的高度和字体大小

原文:http://veright.blog.163.com/blog/static/2834538920101116114716651/ 这几天由于项目原因,需要调整tab 的高度和字体大小,没少折腾人..希望能对有此困扰的朋友,尽点绵薄之力..如果大家找到这里来了.算是找对地方了..哈哈哈 直接上代码,发扬分享至上的互联网精神... int count = tabWidget.getChildCount(); for (int i = 0; i < count; i++) { View vi