質問
他の 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>
あなたが私に与えるかもしれないどんな助けにも感謝します!