Androidの断片の中に断片を表示して隠す方法は?私は2つの断片を活動の中に加えました。メニューを含む1つのフラグメントと1つのフラグメントには、サブメニューが含まれています。私は家、アイデアなどのようなメニューの断片にたくさんのボタンを持っています。アイディアボタンをクリックすると。私はサブメニューを表示する必要があります。もう一度アイデアボタンをクリックすると、サブメニューを非表示にする必要があります。誰かが例を提供することができますか、別のフラグメントの1つのビューフラグメントにアクセスする方法はありますか?どのようにして、アンドロイドの断片内に断片を表示して隠すようにする
これはあなたの "親" の活動にパブリックメソッドを作成し、私のフラグメントで
?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<fragment class="com.gcm.fragment.CommonFragment"
android:id="@+id/the_frag"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<fragment class="com.gcm.fragment.SubFragment"
android:id="@+id/the_frag1"
android:layout_marginTop="130dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
メイン単に
package com.gcm.fragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class CommonFragment extends Fragment implements OnClickListener {
TextView txtIhaveIdea=null;
boolean menuVisible=false;
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.collapsed_menu2, container, false);
txtIhaveIdea=(TextView)layout.findViewById(R.id.txtIhaveAnIdea);
txtIhaveIdea.setOnClickListener(this);
return layout;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(!menuVisible)
{
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
fm.beginTransaction();
Fragment fragOne = new SubFragment();
ft.show(fragOne);
}
else
{
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
fm.beginTransaction();
Fragment fragOne = new SubFragment();
ft.hide(fragOne);
}
}
}
おかげ
は、フラグメントのコードを参照するために参照してくださいhttp://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/FragmentHideShow.htmlアンドロイドのサイトで与えられた/ショーを隠します – potter
@kumarはUの仕事を達成しましたか? – AndroidOptimist