2011-02-04 3 views
0

私は、インテントを使用してコンテンツビューを生成するTabActivityクラスを持っています。特定の状況下では、タブ選択イベントをインターセプトし、メッセージダイアログを開き、選択したインテントを抑制し、元の選択したタブに戻したいと思います。Android:コンテンツビューにデータを入力する前にチェックを実行するTabActivity

私は、TabActivityのコンテンツを(ビューを使用するのではなく)インテント駆動のままにします。

LocalActivityManagerの拡張が必要な​​場合があります。

誰もこれを達成したことはありますか?

// simple example of current code: 

TabHost tabHost = getTabHost(); 
TabSpec ts = tabHost.newTabSpec(tag); 
ts.setIndicator(tabview); 
ts.setContent(new Intent().setClass(this, AHome.class)); 
tabHost.addTab(ts); 

ありがとうございます!

+0

"TabActivityのコンテンツを(ビューを使用するのではなく)インテント駆動したままにします。" - なぜですか? – CommonsWare

+0

@CommonsWare:コンテンツビューには、ビューではなくアクティビティが含まれていなければなりません。アクティビティは既にコンテンツに固有のものです。 MVCのコントローラです。 – paiego

+0

"アクティビティはコンテンツに固有のビルド済みです。本質的にMVCのコントローラです。" MVCは、Androidが発明される前に存在していました。 Wikipediaのこれらのテクノロジーの日付をチェックすることさえできます。したがって、定義上、活動なしでMVCを行うことは可能です。あなたは "クラス"と呼ばれるこれらの魔法のことを使います。代わりに、スタックスペース、ヒープスペース、CPU時間、バッテリ寿命を無駄にするだけで、コードをアクティビティの形式で整理できます。 – CommonsWare

答えて

0

GoogleのスタッフがこのAPIが壊れていることを認めても、答えとしてTabActivityを調べません。 ここで私は何をしているのですか?ターゲットアクティビティでは、条件が満たされていれば、onCreateでこの条件をチェックします。続行しない場合は、前のアクティビティをアクティブにします。

+0

ありがとうございます。 「以前のアクティビティをアクティブにする」方法を教えてください。以前のタブが再選択されるようにしてください。 – paiego

0

AndroidのTabHost srcこの問題に対するかなり単純な解決策です。タブボタンをグラフィカルに「タッチ」させることができますが、まだ選択されていないままにしておけば、選択したタブの処理が妨げられます(すべてのOnTabSelectedリスナーが認識されていることを前提とします)。

だけTabHostクラス拡張:

public class MyTabHost extends TabHost 
{ 
    public MyTabHost(Context context) 
    { 
     super(context); 
    } 

    public MyTabHost(Context context, AttributeSet attrs) 
    { 
     super(context, attrs); 
    } 

    public void setCurrentTab(int index) 
    { 
     // e.g. substitute ? with the tab index(s) for which to perform a check. 
     if (index == ?) 
     { 
      if (/* a block condition exists */) 
      { 
       // Perform any pre-checking before allowing final tab selection 
       Toast.makeText(this.getContext(), "msg", Toast.LENGTH_SHORT).show(); 
       return; 
      } 
     } 
     super.setCurrentTab(index); 
    } 
} 

をそしてTabActivityのために使用されるXMLにMyTabHostTabHostから、あなたの参照を変更:

<com.hos.MyTabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    <LinearLayout  
     android:id="@+id/llTest" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="0dp" 
     > 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="0dp" 
     android:layout_gravity="top" 
     android:layout_weight="1" 
     /> 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom"    
     android:layout_weight="0" 
     /> 

    </LinearLayout> 

</com.hos.MyTabHost> 

覚えておくべきもう一つの事TabActivityでTabActivity.getTabHost()を使用すると、MyTabHostが返されます。たとえば、

MyTabHost mth = (MyTabHost)getTabHost(); 
関連する問題