重新加载当前活动,单击活动选项卡

Ste*_*fan 7 tabs android reload android-activity

我有一个选项卡布局,活动显示在frameLayout中.如何通过再次单击"Home"-Tab从"主页"选项卡重新加载当前活动?

TabTestActivity级

public class TabTestActivity extends TabActivity implements OnClickListener{

    TabHost tabHost;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        //MENÜ////////////////////////////////////////////

            /** TabHost will have Tabs */
            tabHost = (TabHost)findViewById(android.R.id.tabhost);

            /** tid1 is firstTabSpec Id. Its used to access outside. */
            TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
            TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
            TabSpec thirdTabSpec = tabHost.newTabSpec("tid3");
            TabSpec fourthTabSpec = tabHost.newTabSpec("tid4");

            /** TabSpec setIndicator() is used to set name for the tab. */
            /** TabSpec setContent() is used to set content for a particular tab. */
            firstTabSpec.setIndicator(new MyView(this, R.drawable.tabhome, "Home")).setContent(new Intent(this,FirstGroup.class));
            secondTabSpec.setIndicator(new MyView(this, R.drawable.tabmsg, "MSGs")).setContent(new Intent(this,FirstGroup.class));
            thirdTabSpec.setIndicator(new MyView(this, R.drawable.tabprofil, "Profil")).setContent(new Intent(this,FirstGroup.class));
            fourthTabSpec.setIndicator(new MyView(this, R.drawable.tabmehr, "Mehr...")).setContent(new Intent(this,FirstGroup.class));

            /** Add tabSpec to the TabHost to display. */
            tabHost.addTab(firstTabSpec);
            tabHost.addTab(secondTabSpec);
            tabHost.addTab(thirdTabSpec);
            tabHost.addTab(fourthTabSpec);

            tabHost.setCurrentTab(0);
    }

    //LAYOUT OF TABS
    private class MyView extends LinearLayout {
        public MyView(Context c, int drawable, String label) {
            super(c);

            LinearLayout la = new LinearLayout(c);
            //la.setBackgroundColor(Color.parseColor("#3b5091"));
            la.setOrientation(LinearLayout.VERTICAL);
            la.setMinimumHeight(63);
            la.setPadding(0,8,0,0);

            ImageView iv = new ImageView(c);
            TextView tv = new TextView(c);

            iv.setImageResource(drawable);

            setPadding(0,0,2,0);
            setOrientation(LinearLayout.VERTICAL);

            tv.setText(label);
            tv.setGravity(0x01); /* Center */

            tv.setTextColor(Color.WHITE);

            la.addView(iv);
            la.addView(tv);
            addView(la);
            setBackgroundDrawable( getResources().getDrawable(R.drawable.tab_indicator));

        }

    }
Run Code Online (Sandbox Code Playgroud)

FirstGroup的一流

public class FirstGroup extends ActivityGroup {  

        // Keep this in a static variable to make it accessible for all the nesten activities, lets them manipulate the view  
    public static FirstGroup group;  

        // Need to keep track of the history if you want the back-button to work properly, don't use this if your activities requires a lot of memory.  
    private ArrayList<View> history;  

    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
          super.onCreate(savedInstanceState);  
          this.history = new ArrayList<View>();  
          group = this;  

              // Start the root activity withing the group and get its view  
          View view = getLocalActivityManager().startActivity("CitiesActivity", new  
                                            Intent(this,CitiesActivity.class)  
                                            .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP))  
                                            .getDecorView();  

              // Replace the view of this ActivityGroup  
          replaceView(view);  

       }  

    public void replaceView(View v) {  
                // Adds the old one to history  
        history.add(v);  
                // Changes this Groups View to the new View.  
        setContentView(v);  
    }  

    public void back() {  
        if(history.size() > 0) {  
            history.remove(history.size()-1);  
            setContentView(history.get(history.size()-1));  
        }else {  
            finish();  
        }  
    }  

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
    if(keyCode == KeyEvent.KEYCODE_BACK)
    {
    FirstGroup.group.back();
    return true;
    }
    return super.onKeyDown(keyCode, event);
    }

}  
Run Code Online (Sandbox Code Playgroud)

Emi*_*nin 1

我不确定您在寻找什么,但如果您想在用户返回到特定选项卡时更改某些值,您可以在活动的 onResume 方法中执行此操作。