I've got a problem. I have three tabs (tid1, tid2, tid3). I'm properly returning ProfileTab
ID (checked with Toast - tid2) and according to that fact I'm trying to requestFocus()
on a TextView
element from ProfileTab
, so that when someone change tab to ProfileTab
it should focus on that element.
File with Tabs: Main.java
File with ProfileTab: Profile.java
(public)
I did something like this (Main.java):
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
Defines.CURRENT_TAB = tabHost.getCurrentTabTag();
if (Defines.CURRENT_TAB.equals(Defines.profileTab)) {
Profile pTab = new Profile();
pTab.tvGender.requestFocus();
}
}
});
I get:
E/AndroidRuntime( 542): FATAL EXCEPTION: main
E/AndroidRuntime( 542): java.lang.NullPointerException
E/AndroidRuntime( 542): at com.application.co开发者_JS百科re.Main$1.onTabChanged(Main.java:42)
E/AndroidRuntime( 542): at android.widget.TabHost.invokeOnTabChangeListener(TabHost.java:356)
E/AndroidRuntime( 542): at android.widget.TabHost.setCurrentTab(TabHost.java:341)
E/AndroidRuntime( 542): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
E/AndroidRuntime( 542): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
E/AndroidRuntime( 542): at android.view.View.performClick(View.java:2408)
E/AndroidRuntime( 542): at android.view.View$PerformClick.run(View.java:8816)
E/AndroidRuntime( 542): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 542): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 542): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 542): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 542): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 542): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 542): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 58): Force finishing activity com.application.core/.Main
Anyone able to help?
In your
pTab.tvGender.requestFocus();
check if pTab.tvGender
is initialized.
It's better to start your ProfileTab
activity, and send an extra param via an intent.
精彩评论