2012-01-06 1 views
2

私は2つの下部タブ、タブのクリックでアプリケーションを終了したい

"Exit"と "Back"を設定したアプリケーションを作成しています。

ここでは、「終了」タブ(ボタンではない)をクリックしてアプリケーションを終了します。

私はそれを行うことができます、私はアンドロイドでは、実際にアプリケーションを閉じることはできませんが、私は "終了"をクリックしてホーム画面に移動したいと思います。

私はまた、他のリンク

Is quitting an application frowned upon?

EDITあなたの2番目のタブのクリックで

public class Man_age_ur_PhoneActivity extends TabActivity { 

    /** Called when the activity is first created. */ 
    ListView listview; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.homepage); 
     setTabs(); 
    } 

    private void setTabs() 
    { 
     addTab("Exit", R.drawable.tab_exit); 
     addTab("Back", R.drawable.tab_back); 
     //To add more tabs just use addTab() method here like previous line. 
    } 

    private void addTab(String labelId, int drawableId) 
    { 
     TabHost tabHost = getTabHost(); 
//  Intent intent = new Intent(this, c); 
     TabHost.TabSpec spec = tabHost.newTabSpec("" + labelId);  

     View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false); 
     TextView title = (TextView) tabIndicator.findViewById(R.id.title); 
     title.setText(labelId); 
     ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); 
     icon.setImageResource(drawableId); 

     spec.setIndicator(tabIndicator); 
//  spec.setContent(intent); 
     tabHost.addTab(spec); 
     } 
} 
+0

私はあなたがボタンを使うべきではなく、ビューのフリッパー – Nitin

+0

Beenalとタブが、私は、これはあなたが編集した質問を参照してください – Nitin

答えて

0

あなたはまた、例えば参照、一般的にAndroidアプリが終了オプションを持つべきではない、このリンク Android TabWidget detect click on current tab

+0

助けになると思う私の更新の答えをチェックすると思うが、私はhere.Howにタブ変更リスナーを追加したい私は何をすると仮定していますそれ?? – Beenal

1

と一緒にリンクをたどる研究している、あなただけ)(」仕上げを記述する必要があります。 "これにより、以前に開いたアクティビティが終了し、アプリケーションを終了することができます。

0

から撮影この

import android.widget.TabHost; 
import android.widget.TabHost.OnTabChangeListener; 

をインポート

public class Man_age_ur_PhoneActivity extends TabActivity { 

    /** Called when the activity is first created. */ 
    ListView listview; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.homepage); 
     setTabs(); 

    getTabHost().setOnTabChangedListener(new OnTabChangeListener() { 

    @Override 
    public void onTabChanged(String tabId) { 

    int i = getTabHost().getCurrentTab(); 
    Log.i("@@@@@@@@ ANN CLICK TAB NUMBER", "------" + i); 

     if (i == 0) { 
         Log.i("@@@@@@@@@@ Inside onClick tab 0", "onClick tab"); 

         } 
      else if (i ==1) { 
         Log.i("@@@@@@@@@@ Inside onClick tab 1", "onClick tab"); 
      } 

       } 
      }); 



    } 

    private void setTabs() 
    { 
     addTab("Exit", R.drawable.tab_exit); 
     addTab("Back", R.drawable.tab_back); 
     //To add more tabs just use addTab() method here like previous line. 
    } 

    private void addTab(String labelId, int drawableId) 
    { 
     TabHost tabHost = getTabHost(); 
//  Intent intent = new Intent(this, c); 
     TabHost.TabSpec spec = tabHost.newTabSpec("" + labelId);  

     View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false); 
     TextView title = (TextView) tabIndicator.findViewById(R.id.title); 
     title.setText(labelId); 
     ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); 
     icon.setImageResource(drawableId); 

     spec.setIndicator(tabIndicator); 
//  spec.setContent(intent); 
     tabHost.addTab(spec); 
     } 
} 

このコードを使用することができますこの投稿:http://blog.radioactiveyak.com/2010/05/when-to-include-exit-button-in-android.html

本当にしたい場合は、System.exit()を呼び出すこともできます。これは、アプリケーションを完全に終了することが保証されています。

関連する問題