Перезагрузить текущее действие, щелкнув активную вкладку

У меня есть макет вкладок, и действия отображаются в frameLayout. Как я могу перезагрузить текущее действие из вкладки «Главная», снова щелкнув вкладку «Главная»?

TabTestActivity-class

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));

        }

    }

FirstGroup-class

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);
    }

}  
7
задан Lukas Knuth 2 July 2011 в 15:53
поделиться