如何在收到某些通知时更改自定义选项卡的图像

时间:2012-08-14 04:55:34

标签: android

我有一个自定义选项卡,我在后台运行一个服务,在1分钟后点击一个Web服务并从web获取一些数据。现在我希望在收到数据时第一个选项卡图像被更改。 请帮忙。谢谢。

我的代码

 public class MainTabActivity extends TabActivity {

 public static TabHost mTabHost;
 public static TextView offLineText;

private void setupTabHost() {
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);             
    mTabHost.setup();  
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);        
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_test);  
    offLineText=(TextView)findViewById(R.id.offlinetext);
    setupTabHost();  
    mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider); 
    setupTab(new TextView(this), "New Order!","NewOrderActivity.class",R.drawable.neworder);
    setupTab(new TextView(this), "Viewed Orders","ViewedOrderActivity.class",R.drawable.viewd);
    setupTab(new TextView(this), "Settings", "SettingActivity.class",R.drawable.setting);
    setupTab(new TextView(this), "Dashboard","DashboardActivity.class",R.drawable.view);      

}

private void setupTab(final View view, final String tag, final String className, int neworder) {
    View tabview = createTabView(mTabHost.getContext(), tag, mTabHost.getContext().getResources().getDrawable(neworder));

    Intent intent; 
    intent = new Intent().setClass(this, NewOrderActivity.class);
    if (className.equals("NewOrderActivity.class")) {
        intent = new Intent().setClass(this, NewOrderActivity.class);}
    if (className.equals("ViewedOrderActivity.class")) {
        intent = new Intent().setClass(this, ViewedOrderActivity.class);}    
    if (className.equals("SettingActivity.class")) {
        intent = new Intent().setClass(this, SettingActivity.class);}
    if (className.equals("DashboardActivity.class")) {

        intent = new Intent().setClass(this, DashboardActivity.class);
        }  

    TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent); {
    };
    mTabHost.addTab(setContent);
}

private static View createTabView(final Context context, final String text,final Drawable drawable) {

    View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
    TextView tv = (TextView) view.findViewById(R.id.tabsText);
    tv.setText(text); 
    ImageView imageview=(ImageView) view.findViewById(R.id.imgTab);                   
    imageview.setImageDrawable(drawable);

    return view;        

}

}

1 个答案:

答案 0 :(得分:0)