kiwi
kiwi

Reputation: 487

How to get FragmentManager in a class extends LinearLayout?

I've got a class TitleView extends LinearLayout with a button in it. Since there are servral UIs need this class , I included it in those layout xml files. Now I need to start a PreferenceFragment after the button is pressed, but I just can't use getFragmentManager() to obtain FragmentManager to control the PreferenceFragment in TitleView.

Can anyone help me out ? Thanks a lot :)

Upvotes: 1

Views: 3270

Answers (1)

Triode
Triode

Reputation: 11359

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();

Upvotes: 2

Related Questions