フラグメント内で静的メソッドでgetChildFragmentManager()を使用しようとしています。しかし、それはエラーを示し、静的ではない方法を提案します。静的メソッドgetChildFragmentManager()は静的コンテキストから参照できません
Non static method getChildFragmentManager() cannot be referenced from a static context
フラグメント:
public class C_Fragment extends android.support.v4.app.Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_a, container, false);
}
static void updateProductList(){
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (getChildFragmentManager().findFragmentByTag("kz.dreamwings.unimax.fragments.C_Category_A_prudacts")!=null) {
// C_Category_A_prudacts.adapter.notifyDataSetChanged();
Fragment frg = null;
frg = getChildFragmentManager().findFragmentByTag("kz.dreamwings.unimax.fragments.C_Category_A_prudacts");
final FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();
}
}
}, 300);
}
なぜ静的にしていますか? –
@ShreeKrishna他のクラスで使用したい – eluuu
あなたは 'C_Fragment'のインスタンスを持っている限り、別のクラスからメソッドを呼び出すことができます。 – Thilo