如何使用onFinishInflate知道视图何时膨胀

时间:2011-11-13 21:11:23

标签: android tabactivity inflate

我想知道我的TabActivity何时充气,所以我尝试了这段代码

 @Override
 protected void onFinishInflate() {
     super.onFinishInflate();
 }

我收到错误:must override or implement a supertype method
我无法理解为什么这不适用于TabActivity 任何人都可以解释这个吗?

package com.carlsberg.bungle.history;

import com.carlsberg.bungle.Consts;
import com.carlsberg.bungle.R;
import android.app.TabActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public class TabActivityHistoryLauncher extends TabActivity {

    private final String TAG = "TabActivityHistoryLauncher";    
    private TabHost tabHost;
    MyListener myListener;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.tab_activity_history);

        tabHost = (TabHost) findViewById(android.R.id.tabhost);

        Intent int2 = new Intent(this, ActivityTabGroup2.class);
        Intent int1 = new Intent(this, ActivityTabGroup1.class);

        tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);// Divider .9.png 
        setupTab(new TextView(this), getString(R.string.string_incoming),int1);
        setupTab(new TextView(this), getString(R.string.string_outgoing),int2);

        myListener = new MyListener();
        Intent intent = getIntent();

        if(intent != null){
            Bundle extras = intent.getExtras();
            if(extras != null){
                String outgoing = extras.getString(Consts.SWITSH_TO_OUTGOING);
                String incoming = extras.getString(Consts.SWITSH_TO_INCOMING);
                if(incoming != null){
                    tabHost.setCurrentTab(0);
                }else if(outgoing != null){
                    tabHost.setCurrentTab(1);
                }
            }
        }

    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

    }


    private void setupTab(final View view, final String tag, Intent int1) {
        View tabview = createTabView(tabHost.getContext(), tag);

        TabSpec setContent = tabHost.newTabSpec(tag).setIndicator(tabview).setContent(int1);

        tabHost.addTab(setContent);
    }

    private static View createTabView(final Context context, final String text) {
        View view = LayoutInflater.from(context).inflate(R.layout.tab_history_a_tab, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText(text);
        return view;
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if(intent != null){
            Bundle extras = intent.getExtras();
            if(extras != null){
                String outgoing = extras.getString(Consts.SWITSH_TO_OUTGOING);
                String incoming = extras.getString(Consts.SWITSH_TO_INCOMING);
                if(incoming != null){
                    tabHost.setCurrentTab(0);
                }else if(outgoing != null){
                    tabHost.setCurrentTab(1);
                }
            }
        }

    }   


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (myListener != null) {
            unregisterReceiver(myListener);
        }   
    }
    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "onResume ***********************************************************************"); 
        IntentFilter intentFilterInStart = new IntentFilter(Consts.COM_CARLSBERG_INCOMINGSTATUS_ACTION_START );
        IntentFilter intentFilterOutStart = new IntentFilter(Consts.COM_CARLSBERG_OUTGOINGSTATUS_ACTION_START );        
        registerReceiver(myListener, intentFilterInStart);
        registerReceiver(myListener, intentFilterOutStart);     
        //MyListenerIsRegistered = true;        

    }
    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG, "onResume ***********************************************************************");

    }

    // Nested 'listener'
    protected class MyListener extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {

            if (intent.getAction().equals(Consts.COM_CARLSBERG_INCOMINGSTATUS_ACTION_START)) {
                tabHost.setCurrentTab(0);
            }
            if (intent.getAction().equals(Consts.COM_CARLSBERG_OUTGOINGSTATUS_ACTION_START)) {
                tabHost.setCurrentTab(1);
            }           
        }
    }

}

1 个答案:

答案 0 :(得分:3)

Activity不是View。 Activity中没有onFinishInflate方法。在setContentView中使用的视图已经膨胀后,您需要做什么?

我认为尝试在单独的活动中混淆视图是非常糟糕的做法。有关在标签之间共享数据的替代方法,请参阅这些链接