不运行的OnCreate()选项卡上的变化,同一页,第2次卡上、选项、OnCreate

2023-09-07 09:44:54 作者:拼命捂着心脏不让它碎つ

我有4个选项卡在一个页面视图,当我点击第一次在标签中,执行它对应的标签的OnCreate()方法,当我去上相同的其他选项卡页面,再点击previous点击选项卡,然后它的OnCreate()法不执行,为什么?为什么它没有按钮,点击工作意味着每一次我点击了的OnCreate()方法运行。

我的code的标签活动课低于的

  intent1 =新意图()setClass(这一点,keywordxmlparsing.class)。
SPEC1 = tabHost.newTabSpec(活性2)setIndicator(关键字/搜索...)setContent(intent1)。
tabHost.addTab(SPEC1);

intent2 =新意图()setClass(这一点,filter.class)。
spec2 = tabHost.newTabSpec(活动1)setIndicator(过滤搜索)setContent(intent2)。
tabHost.addTab(spec2);
intent3 =新意图()setClass(这一点,OpeningToday.class)。
spec3 = tabHost.newTabSpec(Activity3)setIndicator(今日开盘)setContent(intent3)。
tabHost.addTab(spec3);
intent4 =新的意图(keywordresulttab.this,Map.class);
spec4 = tabHost.newTabSpec(Activity4)setIndicator(地图)setContent(intent4)。
tabHost.addTab(spec4);
 

如果亲爱的我使用

  @覆盖
公共无效onTabChanged(字符串标签){
    // TODO自动生成方法存根
    如果(标签==活性2){




    }
    尝试{
    如果(标签==Activity4){
        意图int​​ent4;
        intent4 =新的意图(keywordresulttab.this,Map.class);
        startActivity(intent4);
        Log.i(suiuawhd,地图类);




                }
 

然后我可以去其他活动意味着使用的

  intent4 =新的意图(keywordresulttab.this,Map.class);
            startActivity(intent4);
 
win10,个别程序没有兼容性选项卡,如何 总是以管理员身份运行

我们可以加载再次活动的选项卡中单击?然后怎么写在

  tabHost.addTab(spec3);
intent4 =新的意图(keywordresulttab.this,Map.class);
spec4 = tabHost.newTabSpec(Activity4)setIndicator(地图)setContent(intent4)。
tabHost.addTab(spec4);
 

解决方案

包含活动选项卡由的ActivityGroup来实现的。当有人更改了标签,相应的活动创建的仅如果有必要的。当移动到任何标签为第二时间,活动已经存在和只有它的窗口被示出。 您应该使用来代替:

  TabHost.setOnTabChangedListener(TabHost.OnTabChangeListener L)
 

TabActivity有独立的活动内容是有点棘手,所以也许你应该考虑使用视图代替。如果没有,你可以使用下面的code到互相访问的所有活动:

得到TabActivity内容的活动情况:

  TabActivity.getLocalActivityManager()。getActivity(字符串名称)
 

其中name是由于在newTabSpec()方法。

从内容的活动得到TabActivity实例:

  FirstTab.getParent()
 

使用这些方法,你可以创建所有活动(使用适当的铸造)之间的通信。例如:

 公共无效onTabChanged(字符串标签){

  如果(label.equals(活性2)){
      SecondActivity SA =(SecondActivity)getLocalActivityManager()getActivity(标签)。
      sa.modifySomething();
  }
}
 

如果你想在标签更改活动,你应该使用:

  tabHost.clearAllTabs()
 

和再次创建所有TabSpecs。

I have 4 tabs in a page view when i click first time on tab it executes it oncreate() method of corresponding tab and when i go to other tab on same page and again click on previous clicked tab then its oncreate() method not execute why?why it is not work as button click means each time i click its oncreate() method run.

my code for tab activity class is below

  intent1 = new Intent().setClass(this, keywordxmlparsing.class);
spec1 = tabHost.newTabSpec("Activity2").setIndicator("keyword/ search...").setContent(intent1);
tabHost.addTab(spec1); 

intent2 = new Intent().setClass(this, filter.class);
spec2 = tabHost.newTabSpec("Activity1").setIndicator("filter search").setContent(intent2);
tabHost.addTab(spec2);
intent3 = new Intent().setClass(this, OpeningToday.class);
spec3 = tabHost.newTabSpec("Activity3").setIndicator("opening today").setContent(intent3);
tabHost.addTab(spec3);
intent4 = new Intent(keywordresulttab.this,Map.class);
spec4 = tabHost.newTabSpec("Activity4").setIndicator("Map").setContent(intent4);
tabHost.addTab(spec4);

dear if i use

    @Override
public void onTabChanged(String label) {
    // TODO Auto-generated method stub
    if(label == "Activity2") {




    }
    try{
    if(label == "Activity4") {
        Intent intent4; 
        intent4 = new Intent(keywordresulttab.this,Map.class);
        startActivity(intent4);
        Log.i("suiuawhd","maps class");




                }

then can i go to other activity means using

  intent4 = new Intent(keywordresulttab.this,Map.class);
            startActivity(intent4);

we can load again activity on tab click??then what to written in place of

     tabHost.addTab(spec3);
intent4 = new Intent(keywordresulttab.this,Map.class);
spec4 = tabHost.newTabSpec("Activity4").setIndicator("Map").setContent(intent4);
tabHost.addTab(spec4);

解决方案

Tabs that contain activities are implemented by means of ActivityGroup. When someone changes a tab, corresponding activity is created only if necessary. When you move to any tab for the second time, the activity is already existing and only its window is shown. You should use instead:

TabHost.setOnTabChangedListener(TabHost.OnTabChangeListener l)

TabActivity with separate activities as a content are a little bit tricky so maybe you should consider using Views instead. If not you can use the following code to access all activities from each other:

get instances of content activities from TabActivity:

TabActivity.getLocalActivityManager().getActivity(String name)

where name is given in newTabSpec() method.

get instance of TabActivity from content activities:

FirstTab.getParent()

Using these method you can create communication between all activities (using proper casting). For example:

public void onTabChanged(String label) {

  if(label.equals("Activity2")) {
      SecondActivity sa = (SecondActivity) getLocalActivityManager().getActivity(label);
      sa.modifySomething();
  }
}

If you want to change activities under tabs you should use:

tabHost.clearAllTabs ()

and create all TabSpecs once again.

 
精彩推荐
图片推荐