4

質問

他の 3 つとは異なるアクティビティまたは Java ファイルから 1 つのタブを実行することは可能ですか?

私のアプリに関するいくつかの情報

私が持っているのは、いくつかの異なるレイアウトを持つ複数のタブ付きアプリです。それらの 1 つは、インタラクティブなグラフィカル レイアウトです。このタブでは、ほとんどが既に機能するように設定したカスタム ビューである必要がありますが、ボタンやスライダーなどのようなウィジェットの行が下部に必要です。マニフェストでメイン アクティビティ ( android:name=".Tab3Activity") として設定すると、ボタンをクリックするとアプリが実行され、テキストが出力されますが、ボタンをクリックするとアプリがクラッシュします。 . ここに私が現在持っているコードがあります

タブの設定

    th.setup();
    TabSpec specs = th.newTabSpec("tag0");
    specs.setContent(R.id.connecttionTab);
    specs.setIndicator("Connection Tab");
    th.addTab(specs);
    specs = th.newTabSpec("tag1");
    specs.setContent(R.id.tab1);
    specs.setIndicator("Zone Manager");
    th.addTab(specs);
    specs = th.newTabSpec("tag2");
    specs.setContent(R.id.tab2);
    specs.setIndicator("",res.getDrawable(R.drawable.ic_tab_vaccontrol));
    th.addTab(specs);
    //Intent intent = new Intent().setClass(this, Tab3Activity.class); tryed using this but
    //with this tab goes ontop of all the other ones and still doesnt work.
    TabSpec spec = th.newTabSpec("Tab3").setIndicator("Graphical Layout").setContent(R.id.tab3);
    th.addTab(spec);

Tab3アクティビティ

public class Tab3Activity extends Activity 
{
    private Tab3 mTab3;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab3);
        mTab3 = (Tab3) findViewById(R.id.tab3_display);
    }

    public void onAddZone(View view)
    {
        mTab3.addZone();
    }
}

Tab3 (ビュー クラス)

public class Tab3 extends View implements OnTouchListener
{
    public Tab3(Context context, AttributeSet attrs)
    {
        super (context, attrs);
        setFocusable(true);
        setFocusableInTouchMode(true); 
        setOnTouchListener(this);
        requestFocus();
    }
    @Override
    protected void onDraw(Canvas canvas)
    {
        super.onDraw(canvas);
        //drawings
        invalidate();
    }
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
        //onTouch
        return true;
    }   
    public void addZone() 
    {
        //String w = "W~20~0~0~0~0~0";
        Log.d("ZoneSize", "Zone set");
        //MyApplication.preferences.edit().putString( "ZoneSize", w ).commit();
        //MyApplication.preferences.edit().putBoolean("ZoneSizeReady", true).commit();
    }
}

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:id="@+id/myLayout"
    android:orientation="vertical"
    android:layout_height="match_parent" >

    <com.zone.manager.Tab3
        android:id="@+id/tab3_display"
        android:layout_width="fill_parent"
        android:layout_height="620dp" />

         <LinearLayout
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:layout_height="match_parent" >   

            <Button
                android:id="@+id/addZone"
                android:layout_width="wrap_content"
                android:onClick="onAddZone"
                android:layout_height="wrap_content"
                android:text="Add Zone" />

            <Button
                android:id="@+id/helpZone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Help" />

            <SeekBar
                android:id="@+id/seekBar1"
                android:paddingTop="9dp"
                android:layout_width="179dp"
                android:layout_height="wrap_content" />

        </LinearLayout>
</LinearLayout>

あなたが私に与えるかもしれないどんな助けにも感謝します!

4

1 に答える 1

3

クラッシュ ログを投稿することを期待していますが、古いタブ アプローチを使用しないことをお勧めします (もちろん、それらのタブを正確に必要としているクライアントによって強制された場合を除きます)。Android の UI パターンは、タブ ウィジェットの時代から大きく進化しました。

タブを実装する最新の方法は、ActionBarFragments APIを使用することです。これらは Honeycomb から存在していましたが、Android SDK マネージャーでダウンロードできるサポート ライブラリとして以前の Android バージョンで利用できます。フラグメントベースのアプローチにより、頭痛の種が大幅に軽減されます。

あなたの主な質問については、さまざまなアクティビティから何かを起動して何を達成しようとしているのかは明確ではありませんが、あるアクティビティから長時間実行されるタスクを起動し、結果を別のアクティビティに返す必要がある場合は、読みたいと思うかもしれませんサービスにアップします(特に、IntentServiceが探している可能性が最も高いです)

于 2012-06-20T11:38:52.533 に答える