how to know when view has inflated using the onFinishInflate

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

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

回答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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!