マイmain.xmlレイアウトは単に二つのボタン、以下を示しコンテンツエリアを、含まれています私の場合、LayoutInflaterを使用して古いコンテンツを削除して新しいコンテンツを表示するにはどうすればよいですか?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/myBtns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/btn_one"
android:layout_width="100dip"
android:layout_height="30dip"
android:text="button one"
/>
<Button
android:id="@+id/btn_two"
android:layout_width="100dip"
android:layout_height="30dip"
android:text="button two"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/content_area"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<!--different button press will embed different content here-->
</LinearLayout>
</LinearLayout>
私は各ボタンを押して自分のタブ状機能を作成したいですボタンの下のコンテンツ(content_area
)を更新します。だから、私は2つの他のコンテンツのレイアウトを用意しています
content_one.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView.../>
<Button .../>
</LinearLayout>
がcontent_two.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Gallery.../>
<Button .../>
</LinearLayout>
をすべての私の単純なコードでは、私は希望、上記示しました。次のような機能を実装する:
main.x mlの:
button_one
が押されたときに、content_one.xmlはcontent_area
のmain.xmlに埋め込まれます。button_two
が押されたときには、main.xmlの
content_area
はタブ状機能を作成するには、ボタンを使用することを意味content_two.xml
に更新されます。
は、私が試した:上記のコードは、部分的に作業さ
button_one.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
LayoutInflater inflater = (LayoutInflater)MyActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflatedView = inflater.inflate(R.layout.content_one, null);
LinearLayout contentArea= (LinearLayout) findViewById(R.id.content_area);
contentArea.addView(inflatedView);
}
});
button_two.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
LayoutInflater inflater = (LayoutInflater)MyActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflatedView = inflater.inflate(R.layout.content_two, null);
LinearLayout contentArea= (LinearLayout) findViewById(R.id.content_area);
contentArea.addView(inflatedView);
}
});
、私は何を意味するbutton_one
が押されたときbutton_two
が押されたときに、content_area
がcontent_one.xml、またはを示すことです、 content_area
にはcontent_two.xmlが表示されています。
しかし、いずれかのボタンを最初に押した後、もう一方のボタンを押すと、コンテンツは古いボタンでトリガされたコンテンツに残ります。私はbutton_two
を押すと、例えば、アプリケーションが最初にロードされ、まずbutton_one
を押すと、content_one.xmlが表示され、その後に、コンテンツは、はcontent_one.xmlに残っています。
私の質問はLayoutInflaterを使用したときに、古いコンテンツを削除し、新しいコンテンツを表示する方法ですか?