gpt4 book ai didi

android - 如何使用 onFinishInflate 知道 View 何时膨胀

转载 作者:搜寻专家 更新时间:2023-11-01 09:11:20 25 4
gpt4 key购买 nike

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

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

我收到错误:必须覆盖或实现父类(super class)型方法
我不明白为什么这在 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);
}
}
}

}

最佳答案

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

我认为在单独的 Activity 中尝试混淆 View 是非常糟糕的做法。查看这些链接以了解在选项卡之间共享数据的替代方法

关于android - 如何使用 onFinishInflate 知道 View 何时膨胀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8114772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com