0

Intents を使用してコンテンツ ビューを設定する 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);

ありがとう!

4

2 に答える 2

0

私は、TabActivity で答えを探すつもりはありません (Google のスタッフでさえ、この API が壊れていることを認めています)。これが私がすることです-ターゲットアクティビティでは、onCreateでこの条件を確認し、条件が満たされた場合は続行し、そうでない場合は-前のアクティビティをアクティブにします

于 2011-02-04T05:48:07.717 に答える
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 で参照をTabHostからMyTabHostに変更します。

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

もう 1 つ覚えておくべきことは、TabActivity で TabActivity.getTabHost() を使用すると、MyTabHost が返されるということです。例えば:

MyTabHost mth = (MyTabHost)getTabHost();
于 2011-02-05T08:27:50.430 に答える