我有一个TitleView类,其中扩展了带有按钮的LinearLayout。由于存在需要该类的servical UI,因此我将其包含在这些布局xml文件中。现在,我需要在按下按钮后启动一个PreferenceFragment,但是我只是不能使用getFragmentManager()获取FragmentManager来控制TitleView中的PreferenceFragment。

谁能帮我吗 ?非常感谢 :)

最佳答案

class TitleView extends LinearLayout
{

    private FragmentActivity mActivity;

    /**
     * @param of type null
     * @return mActivity of type FragmentActivity
     * getter function for mActivity
     * @since May 3, 2013
     * @author rajeshcp
     */
    public FragmentActivity getmActivity() {
        return mActivity;
    }

    /**
     * @param mActivity of type FragmentActivity
     * @return of type null
     * setter function for mActivity
     * @since May 3, 2013
     * @author rajeshcp
     */
    public void setmActivity(FragmentActivity mActivity) {
        this.mActivity = mActivity;
        mActivity.getSupportFragmentManager();
    }

    public TitleView(Context context) {
        super(context);
    }

}

((TitleView)findViewbyId(R.id.your_lay_out_id)).setmActivity(yourFragmentActivity);

mActivity.getSupportFragmentManager();

10-08 20:21