Reputation: 11
@EView public class BaseButton extends Button implements OnClickListener { private SherlockFragment nextFragment;
public BaseButton(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public void onClick(View v) {
// TODO Auto-generated m ethod stub
//how to get fragment manager?
FragmentManager fragmentManager = app.getFragmentManager();
}
public SherlockFragment getNextFragment() {
return nextFragment;
}
public void setNextFragment(SherlockFragment nextFragment) {
this.nextFragment = nextFragment;
}
}
I want to add next fragment dynamically to my custom view using android annotations
Upvotes: 1
Views: 1401
Reputation: 1385
View shouldn't be aware where it's placed (Fragment or Activity). You should find View and set OnClickListener externally or provide FragmentManager (I don't think if it's best idea to use FragmentManager inside View like in your sample).
Upvotes: 2
Reputation: 387
Supposed your FragmentActivity is MainActivity.class to get FragmentManager
((MainActivity)context).getSupportFragmentManager();
Note : check import of MainActivity
Upvotes: -2