如何知道什么时候视图使用onFinishInflate已经飙升 [英] how to know when view has inflated using the onFinishInflate

查看:916
本文介绍了如何知道什么时候视图使用onFinishInflate已经飙升的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么时候我的 TabActivity 已膨胀所以我想这code

  @覆盖
 保护无效onFinishInflate(){
     super.onFinishInflate();
 }

我得到的错误:必须覆盖或实现超方式结果
我不明白这是为什么没有在TabActivity工作。结果
任何人都可以explane吗?

 包com.carlsberg.bungle.history;进口com.carlsberg.bungle.Consts;
进口com.carlsberg.bungle.R;
进口android.app.TabActivity;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.Window;
进口android.widget.TabHost;
进口android.widget.TabHost.TabSpec;
进口android.widget.TextView;
进口android.content.BroadcastReceiver;
进口android.content.Context;
进口android.content.Intent;
进口android.content.IntentFilter;公共类TabActivityHistoryLauncher扩展TabActivity {    私人最终字符串标记=TabActivityHistoryLauncher;
    私人TabHost tabHost;
    myListener的myListener的;
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        的setContentView(R.layout.tab_activity_history);        tabHost =(TabHost)findViewById(android.R.id.tabhost);        意图INT2 =新意图(这一点,ActivityTabGroup2.class);
        意图INT1 =新意图(这一点,ActivityTabGroup1.class);        。tabHost.getTabWidget()setDividerDrawable(R.drawable.tab_divider); //分频器.9.png
        setupTab(新的TextView(本),的getString(R.string.string_incoming),INT1);
        setupTab(新的TextView(本),的getString(R.string.string_outgoing),INT2);        myListener的=新myListener的();
        意向意图= getIntent();        如果(意向!= NULL){
            捆绑额外= intent.getExtras();
            如果(临时演员!= NULL){
                字符串传出= extras.getString(Consts.SWITSH_TO_OUTGOING);
                字符串传入= extras.getString(Consts.SWITSH_TO_INCOMING);
                如果(来袭!= NULL){
                    tabHost.setCurrentTab(0);
                }否则如果(发送!= NULL){
                    tabHost.setCurrentTab(1);
                }
            }
        }    }    @覆盖
    保护无效onFinishInflate(){
        super.onFinishInflate();    }
    私人无效setupTab(最终查看视图,最后字符串的标签,意图INT1){
        查看TabView的= createTabView(tabHost.getContext(),标签);        则tabspec setContent = tabHost.newTabSpec(标签).setIndicator(TabView的).setContent(INT1);        tabHost.addTab(setContent);
    }    私有静态视图createTabView(最终上下文的背景下,最终字符串文本){
        查看查看= LayoutInflater.from(上下文).inflate(R.layout.tab_history_a_tab,NULL);
        TextView的电视=(TextView中)view.findViewById(R.id.tabsText);
        tv.setText(文本);
        返回视图。
    }    @覆盖
    保护无效onNewIntent(意向意图){
        super.onNewIntent(意向);
        如果(意向!= NULL){
            捆绑额外= intent.getExtras();
            如果(临时演员!= NULL){
                字符串传出= extras.getString(Consts.SWITSH_TO_OUTGOING);
                字符串传入= extras.getString(Consts.SWITSH_TO_INCOMING);
                如果(来袭!= NULL){
                    tabHost.setCurrentTab(0);
                }否则如果(发送!= NULL){
                    tabHost.setCurrentTab(1);
                }
            }
        }    }
    @覆盖
    保护无效的onDestroy(){
        super.onDestroy();
        如果(myListener的!= NULL){
            unregisterReceiver(myListener的);
        }
    }
    @覆盖
    保护无效onResume(){
        super.onResume();
        Log.d(TAG,onResume ****************************************** ****);
        IntentFilter的intentFilterInStart =新的IntentFilter(Consts.COM_CARLSBERG_INCOMINGSTATUS_ACTION_START);
        IntentFilter的intentFilterOutStart =新的IntentFilter(Consts.COM_CARLSBERG_OUTGOINGSTATUS_ACTION_START);
        registerReceiver(myListener的,intentFilterInStart);
        registerReceiver(myListener的,intentFilterOutStart);
        // MyListenerIsRegistered = TRUE;    }
    @覆盖
    保护无效的onPause(){
        super.onPause();
        Log.d(TAG,onResume ****************************************** ****);    }    //嵌套的'听众'
    保护类myListener的扩展广播接收器{        @覆盖
        公共无效的onReceive(上下文的背景下,意图意图){            如果(intent.getAction()。等于(Consts.COM_CARLSBERG_INCOMINGSTATUS_ACTION_START)){
                tabHost.setCurrentTab(0);
            }
            如果(intent.getAction()。等于(Consts.COM_CARLSBERG_OUTGOINGSTATUS_ACTION_START)){
                tabHost.setCurrentTab(1);
            }
        }
    }}


解决方案

这是活动是不是视图。有一个在活动没有 onFinishInflate 方法。它是什么,你需要您在使用视图的setContentView 已膨胀后怎么办?

我相信这是非常不好的做法,试图惹的意见在一个单独的活动。看到这些链接,共享选项卡之间进行数据的另一种方式。

I want to know when my TabActivity has inflated so i tried this code

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

i get the error: must override or implement a supertype method
I cannot understand why that is not working in the TabActivity.
Can Anyone explane this?

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

}

解决方案

An Activity is not a View. There is no onFinishInflate method in Activity. What is it that you need to do after the View you use in setContentView has inflated?

I believe it is very bad practice to try to mess with views in a separate activity. See these links for an alternative way to share data between tabs

这篇关于如何知道什么时候视图使用onFinishInflate已经飙升的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆