私は現在アプリケーションを開発していますが、修正するためにハックすることができる小さなエラーが発生しましたが、なぜ私のエラー発生する。私は3つのタブを作成するTabWidgetを使用するタブ付きのインターフェイスを持っています。私のエラーは、私がViewFlipperを配置した最初のタブにあります。 ViewFlipperは、2つの異なるビュー(2つのViewStubを使用して2つの以前に設計されたレイアウトに接続する)間を移動することを目的としています。基本的に最初のビューには、現在のTabのViewFlipperを次の(または指定された)view \ layoutに変更するボタンがあります。私のエラーは、初めてアプリケーションを起動したときに発生します。 ViewFlipperへの最初のリクエスト(showNextまたはshowPreviousまたはsetDisplayChild)は登録されていません。次のプレス(およびその後のボタンの押下)は、ディスプレイを正しく変更します。 LogCatを使用して、ボタンが実際に登録されたonClick関数(xmlレイアウトで定義されている)を実際に呼び出しているかどうかを確認し、ボタンがクリックを登録しているかどうかを確認しました。この問題は、特にViewFlipperビューへの最初の呼び出しが変更され、その後のすべての呼び出しが完全に機能します。AndroidのViewFlipperとshowNext()またはshowPreviousの最初の呼び出しに関する非常に奇妙なエラー
ご協力いただければ幸いです。私は必要に応じてコードを投稿したいと思っていますが、かなり時間がかかります。
EDIT:コードを追加しました。
メインXML
<TabHost 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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ViewFlipper android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- View 1 -->
<ViewStub android:id="@+id/stub1"
android:inflatedId="@+id/subTree1"
android:layout="@layout/layout_tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!-- View 2 -->
<ViewStub android:id="@+id/stub2"
android:inflatedId="@+id/subTree2"
android:layout="@layout/layout_tab12"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</ViewFlipper>
<ViewFlipper android:id="@+id/tab2"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<!-- View 1 -->
<ViewStub android:id="@+id/stub3"
android:inflatedId="@+id/subTree3"
android:layout="@layout/layout_tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ViewFlipper>
<ViewFlipper android:id="@+id/tab3"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<!-- View 1 -->
<ViewStub android:id="@+id/stub4"
android:inflatedId="@+id/subTree4"
android:layout="@layout/layout_tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!-- View 2 -->
</ViewFlipper>
</FrameLayout>
</LinearLayout>
</TabHost>
タブ1つのXML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabone"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:onClick="onButtonClick"/>
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Tab 1" />
</LinearLayout>
アプリケーションコード
TabHost mTabHost;
TextView textCurrent;
ViewFlipper viewFlipper;
String tag = "Tag";
int value = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.tab1));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.tab2));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.tab3));
mTabHost.setCurrentTab(0);
mTabHost.setOnTabChangedListener(this);
}
public void onButtonClick(View v)
{
if(v.getId() == R.id.button1)
{
Log.d(tag, "Button Pressed");
viewFlipper = (ViewFlipper) findViewById(R.id.tab1);
viewFlipper.showNext();
/*
//HACK TO GET NEXT BUTTON WORKING
value++;
if(value == 1)
viewFlipper.showNext();
*/
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) { //Back key pressed
mTabHost = getTabHost();
if(mTabHost.getCurrentTab() == 0)
{
//Things to Do
viewFlipper = (ViewFlipper) findViewById(R.id.tab1);
viewFlipper.showPrevious();
}
else
{
finish();
}
return true;
}
return super.onKeyDown(keyCode, event);
}
public void onTabChanged(String arg0) {
// TODO Auto-generated method stub
if(arg0.equals("tab_test1"))
{
Log.d(tag, "Tab 1 Accessed");
viewFlipper = (ViewFlipper) findViewById(R.id.tab1);
int index = viewFlipper.indexOfChild(findViewById(R.id.subTree1));
viewFlipper.setDisplayedChild(index);
}
}
ViewStubを使用する必要があるのだろうかと思います。あなたはスタブを実際のレイアウトに置き換えて同じセットアップを試すことができますか? –
Yipは今働くようです....非常に奇妙です。私は何とか他のレイアウトを使用する必要があります - ViewFlipperは、viewFlipper内でRelativeLayoutを使用することに問題があるようでした。 – user901898
エラーを修正できる方法があるかどうかを知りたいだけです。 ViewStubsでエラーが発生する(つまり、使用時には表示されませんが)、実際にViewStubsを使用して(レイアウトシステムを大幅に簡素化して)使いたいと思います。 – user901898