0
我有一個帶有FrameLayout的tabhost視圖,一旦在我的java內部選擇了一個選項卡,我會創建新的intent並調用FrameLayout中的不同活動。Android Access TabHost父視圖中的視圖
現在我試圖從父活動訪問子活動(FrameLayout中的一個),但它不起作用。這裏有雲示例代碼
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.book_download_activity);
tabHost = getTabHost();
addTab("Download File", R.drawable.ic_action_download,DownloadActivity.class);
}
private void addTab(String labelId, int drawable, Class<?> c) {
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec(labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.custom_tabs, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawable);
icon.setScaleType(ImageView.ScaleType.FIT_CENTER);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
既然叫DownloadActivity活動都有它自己的XML佈局,我想從這個活動訪問
錯誤日誌
02-15 06:08:09.147: E/AndroidRuntime(2588): FATAL EXCEPTION: main
02-15 06:08:09.147: E/AndroidRuntime(2588): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.utext.unext/com.utext.unext.BookFrame}: java.lang.NullPointerException
02-15 06:08:09.147: E/AndroidRuntime(2588): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-15 06:08:09.147: E/AndroidRuntime(2588): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-15 06:08:09.147: E/AndroidRuntime(2588): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-15 06:08:09.147: E/AndroidRuntime(2588): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-15 06:08:09.147: E/AndroidRuntime(2588): at android.os.Handler.dispatchMessage(Handler.java:99)
02-15 06:08:09.147: E/AndroidRuntime(2588): at android.os.Looper.loop(Looper.java:137)
02-15 06:08:09.147: E/AndroidRuntime(2588): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-15 06:08:09.147: E/AndroidRuntime(2588): at java.lang.reflect.Method.invokeNative(Native Method)
02-15 06:08:09.147: E/AndroidRuntime(2588): at java.lang.reflect.Method.invoke(Method.java:511)
02-15 06:08:09.147: E/AndroidRuntime(2588): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-15 06:08:09.147: E/AndroidRuntime(2588): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-15 06:08:09.147: E/AndroidRuntime(2588): at dalvik.system.NativeStart.main(Native Method)
02-15 06:08:09.147: E/AndroidRuntime(2588): Caused by: java.lang.NullPointerException
02-15 06:08:09.147: E/AndroidRuntime(2588): at com.utext.unext.BookFrame.createView(BookFrame.java:190)
02-15 06:08:09.147: E/AndroidRuntime(2588): at com.utext.unext.BookFrame.onCreate(BookFrame.java:62)
02-15 06:08:09.147: E/AndroidRuntime(2588): at android.app.Activity.performCreate(Activity.java:5104)
02-15 06:08:09.147: E/AndroidRuntime(2588): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-15 06:08:09.147: E/AndroidRuntime(2588): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-15 06:08:09.147: E/AndroidRuntime(2588): ... 11 more
希望它是有意義
這僅僅是標籤添加到佈局,並呼籲他們的活動我所尋找的是標籤訪問活動的XML佈局 – 2013-02-15 06:43:40